March 2013
Beginner to intermediate
580 pages
16h 11m
English
Now that you have code to request location updates as broadcast Intents, you need to have a way to receive them. RunTracker will need to be able to receive them whether or not any UI components, or even the application process, are running, so the best place to handle it is with a standalone BroadcastReceiver registered in the manifest.
To keep things simple, create LocationReceiver to log out the locations it receives.
Listing 33.5 Basic LocationReceiver (LocationReceiver.java)
public class LocationReceiver extends BroadcastReceiver {
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// If you got a Location extra, use it
Location loc = (Location)intent ...Read now
Unlock full access