Thursday, December 27, 2012

Re: [android-developers] Re: Location Listener Question

On Thu, Dec 27, 2012 at 10:39 AM, Jake Colman <colman@ppllc.com> wrote:
> I think I know why my listener is not always firing but I'm not sure
> what to do about it. The request for location updates is coming from a
> Service that is periodically updating a widget. Looking the logcat, it
> looks like the service gets destroyed before I received the update. If
> the service is destroyed, the listener object is gone too!
>
> How does one typically deal with this situation?

The only reason a service would be destroyed within that short a
period of time is if somebody stops it. For example, an IntentService
calls stopSelf() when onHandleIntent() ends (if there is no more work
queued up).

Handling periodic locations, triggered by alarms, is tricky, not only
in the location handling but in making sure the WakeLock and
everything is behaving as expected. I tossed together a simple
LocationPoller to demonstrate the sort of stuff that's required:

https://github.com/commonsguy/cwac-locpoll

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 4.4 Available!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment