Suppose I use BroadcastReceiver to receive events(intents) that awake the phone even if it is in deep sleep mode (such as incoming data packet on a socket, or incoming text message). Then I forward received data to an IntentService for processing. Should I use WakeLock?
If I do not use wakelock, can I be sure that the device will not go to sleep mode until the intent queue of my service is empty (and hence the service is stopped)? (Suppose processing can take long time).
If WakeLock is required, then where and when should I create and aquire it, and when should I release it? I would like to release WakeLock immediatlely after the intent queue of the service is empty.
Thank you in advance
The device is not guaranteed to stay awake long enough to get through the intent queue. If it's really important that you handle intents promptly, your best bet is to do something like this in your onHandleIntent
:
mWakeLock.acquire(); // mWakeLock should be set to be reference counted
// (do work)
mWakeLock.acquire(1000); // hopefully long enough to get to the next item
mWakeLock.release();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With