O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required