Receiving Broadcast Location Updates

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)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​L​o​c​a​t​i​o​n​R​e​c​e​i​v​e​r​ ​e​x​t​e​n​d​s​ ​B​r​o​a​d​c​a​s​t​R​e​c​e​i​v​e​r​ ​{​
 ​ ​p​r​i​v​a​t​e​ ​s​t​a​t​i​c​ ​f​i​n​a​l​ ​S​t​r​i​n​g​ ​T​A​G​ ​=​ ​"​L​o​c​a​t​i​o​n​R​e​c​e​i​v​e​r​"​;​

 ​ ​@​O​v​e​r​r​i​d​e ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.