05-30-2012 12:05 PM
I read somewhere that a background thread should not reschedule tasks with too high a frequency, because it will prevent the device entering its "idle state" and therefore drain the battery.
I could not find any documentation on this, can anyone please confirm and possibly link to the docs, if they exist? I have a background app that may need to poll for changes every few minutes or even seconds depending on the risk of battery drain.
Presumably, when the power-off button is pressed, the device is actually off and not in some idle state? Or is there some stuff going on while it is "off"?
Thanks very much.
Solved! Go to Solution.
05-30-2012 04:35 PM
I'm not sure about the first part.
The device can go into idle mode even when background threads are running unless you specifically request to stay awake.
However, draining the battery can happen even if the device is in idle screen (for example, multiple connections).
Here are some ideas to improve battery consumption:
a. Code according to event - Listen to the events of the phone (battery changes, power charge, WIFI status, etc) and act accordingly. For example, shot down your application when battery reaches 29% and reactivate it when connecting to charger.
B. Set up different Configuration modes - For example, most people sleeps between 00:00 to 06:00. During that time, you can shot down your application and start it up a bit before. This way, most people would wake and your application would be up to date as if it worked all night long...
C. You talked about making frequent connections. Consider using the push service. This way you would make connections only when you really need to.
d. Move as much as possible processing to the server. The less work your application would do, it will consume less power.
Hope that helps,
05-30-2012 04:51 PM
Yes, this is true: frequently repeating tasks will prevent the device from going into a low-power (standby) mode. It is not simply "idle" mode with the screen turned off - it is a deeper sleep, so to speak. Make sure you reschedule such tasks to some very low frequency (once in a few hours) when the application is not active and the screen is black. Schedule them at the regular intervals when the aplication become active again.
05-31-2012 05:56 AM
This confirms what I'd read - it would be nice if there was some article or guide that would explain fully how it works and the timings involved.
My own app will not be making connections as such, but polling for data-usage on the device. I ran a test last night doing persistent store commits every 5 seconds and the battery drain was the same as another handset. So I think it's ok for now. In my final product, the frequency will be lower than once per 5 secs - it was just a test. There may be a way I can make the polling frequency more intelligent later on, but data/byte usage could happen at any time while the device is on unfortunately.
Thanks to you both for the info.