>>>>> "MM" == Mark Murphy <mmur...@commonsware.com> writes:

   MM> On Thu, Dec 27, 2012 at 10:39 AM, Jake Colman <col...@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?

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

Hmmmm.  The service's onHandleIntent is basically a set of 'if/else'
clauses for the intents I am looking for with a final 'else' for any
unrecognized intent.  After that final 'else' there is no other code.

In my logcat I see that the code for determining the location has been
triggered (I have debug statements showing me the available and best
providers) but then I immediately see the service's onDestroy method
logging that it was called.  My test phone is a vanilla HTC EVO 4G
running CM7 with nothing extra installed on it.

Is there anything else that can cause the service to be destroyed?  In
case it matters, the service is being started from the onReceive method
of an AppWidgetProvider.  Is it possible that the service's life cycle
is shortened in that instance?  Either way, how do I make sure I stay
alive long enough for my Listener to get an update?

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

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

Thanks for this code.  Now I need to study it!

-- 
Jake Colman -- Android Tinkerer

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to