What difference does it make to register location updates with location listener and pending intents.?
In the Google I/O Session on Android Pro Tips, http://www.google.com/even开发者_JAVA技巧ts/io/2011/sessions/android-protips-advanced-topics-for-expert-android-app-developers.html , the speaker mentions to register location updates using pending intents over location listener ?? Does anyone know the reason behind it ?
Location listener is an interface implemented by your class, which means that you class (and your activity/app) must be in memory (app/service must be active) to be called.
OTOH, with pending intents OS can start a service and deliver the intent, meaning that your app does not need to be active at that time.
So if you need to get location updates at all times, then use pending intents. They will wake your app and deliver the intent. You should use this with a Service, so that a service is started and does the required work in the background.
But if you only need location updates while your app is active then use location listener. Where you implement the listener is up to your architecture.
精彩评论