views:

58

answers:

2

My app periodically checks the location using an alarm to a BroastcastReceiver that starts a service. I know I should acquire a wakelock before I start the service but my question is when can I release it?

If I release the wakelock after calling requestLocationUpdates, can the device go to sleep and not call my LocationListener or will the device always wake to deliver updates and stay awake until the callback has returned? I'm reluctant to hold onto the wakelock because that would prevent the device from sleeping between updates until I'm done with the location.

A: 

You could take a look at CommonsGuy's WakefulService which, according to the documentation can handle the partial wakelock stuff for you.

Christopher
The question is not "How to use a WakeLock" but "Is a WakeLock necessary?"
noah
The answer is yes, because you're starting a `Service`, as I believe the SDK documentation mentions.
Christopher
The complete question is: Is a WakeLock necessary when calling requestLocationUpdates in order to guarantee updates are received when they are available?
noah
I believe you just have to hold a wakelock until the `Service` has started up and you have called `requestLocationUpdates`. At that point, the service is running and can receive the location updates; the wakelock can be released, the `onReceive` method will have completed and the device can potentially go back to sleep.
Christopher