Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit dd2aee0

Browse files
author
Lyla
committed
6.01 Using Services
1 parent dd9674e commit dd2aee0

4 files changed

Lines changed: 151 additions & 256 deletions

File tree

app/src/androidTest/java/com/example/android/sunshine/app/TestFetchWeatherTask.java

Lines changed: 0 additions & 104 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
<provider
4141
android:authorities="com.example.android.sunshine.app"
4242
android:name=".data.WeatherProvider" />
43+
44+
<service android:name=".service.SunshineService"/>
4345
</application>
4446

4547
</manifest>

app/src/main/java/com/example/android/sunshine/app/ForecastFragment.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.example.android.sunshine.app;
1717

18+
import android.content.Intent;
1819
import android.database.Cursor;
1920
import android.net.Uri;
2021
import android.os.Bundle;
@@ -32,6 +33,7 @@
3233
import android.widget.ListView;
3334

3435
import com.example.android.sunshine.app.data.WeatherContract;
36+
import com.example.android.sunshine.app.service.SunshineService;
3537

3638
/**
3739
* Encapsulates fetching the forecast and displaying it as a {@link ListView} layout.
@@ -179,9 +181,10 @@ void onLocationChanged( ) {
179181
}
180182

181183
private void updateWeather() {
182-
FetchWeatherTask weatherTask = new FetchWeatherTask(getActivity());
183-
String location = Utility.getPreferredLocation(getActivity());
184-
weatherTask.execute(location);
184+
Intent intent = new Intent(getActivity(), SunshineService.class);
185+
intent.putExtra(SunshineService.LOCATION_QUERY_EXTRA,
186+
Utility.getPreferredLocation(getActivity()));
187+
getActivity().startService(intent);
185188
}
186189

187190
@Override

0 commit comments

Comments
 (0)