I have an activity with some Handlers
that are being executed at intervals no more than 5 minutes. The activity is launched from a BroadcastReceiver
and may be launched with the screen off waiting for the user to grab the phone and get the user input, when this happens, the activity onPause()
is called so for sure CPU is in sleep mode. I have not set the activity to turn screen on because I want to save as much battery as possible.
I've tested it with my phone and works really well, while screen is off all Handlers
execute all the code they have to run. If I turn the screen on and off while the activity is open everything works fine.
Now, I've read everywhere that some devices does not work as expected when screen goes off and CPU sleeps, most of the times with accelerometers. Now my question is, do I need to acquire a WakeLock
so the CPU does not sleep while my activity is open? I really want to know this because, as I said before, I don't want to 'waste' battery by acquiring an expensive WakeLock
.
I would prefer a detailed answer of a person that really knows how this works.
KEEP_SCREEN_ON
, that's why sometimes the activity is open with the screen off (or the screen turns off while the activity is open). – Linin