1

I'm using the wakeful service pattern of the commonsware books. My problem is to handle the service instance. My goal is to check every X minutes for the current location of the user (doesn't have to be very accurate), and do some logic with that. The problem occures when I'm registering for location updates. I put locationManager.removeUpdates(locationListener) on the "onDestroy" function but it still keep throwing me warnings from the messageQueue that his messsages are going to a dead thread. I can't let go from the location updates because if no other app is on the device, I'll get old, not relevant, locations.

What can I do?

Thanks,

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Shahar
  • 541
  • 2
  • 7
  • 22

1 Answers1

0

WakefulIntentService is not suitable for this, as the service will shut down once onHandleIntent() returns. Instead, look at something like LocationPoller, which uses a regular Service along with a WakeLock, keeping the service running just long enough to get a location fix before shutting down the service.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is one of your books writes about this LocationPoller? – Shahar Jul 20 '12 at 15:57
  • @Shahar: No, sorry, I have not mentioned `LocationPoller` in my book. Someday I might. – CommonsWare Jul 20 '12 at 16:33
  • Do this locationpoller know to defend himself from task killers and reboot? – Shahar Aug 16 '12 at 15:05
  • @Shahar: Nothing can defend itself from task killers and reboot. `LocationPoller` does not have its own alarms -- whatever schedules the alarms would need to take into account task killers, reboots, etc. – CommonsWare Aug 16 '12 at 15:07
  • The wakeful service knows to be launch even if a task killer kills him. And he knows to start on reboot. Do locationPoller knows it too? – Shahar Aug 16 '12 at 23:53
  • @Shahar: "The wakeful service knows to be launch even if a task killer kills him. And he knows to start on reboot." -- not really. I have some hooks to help you manage those states, that's all. "Do locationPoller knows it too?" -- no. – CommonsWare Aug 17 '12 at 11:20
  • I'm sorry if I'm misspelling, I need a service that raise by alarm as wakeful service does (thats the avoiding of the task killer that I was talking about), and relaunch after boot. The service basically need to pull the location and then gone, can you instruct me how to combine wakful service with the locationPoller? Many thanks!! – Shahar Aug 17 '12 at 14:43