I'm trying to run a background task which runs every minute or so for an android application but I am struggling to ensure that the task actually runs every minute. I've tried a variety of approaches from using SystemClock.sleep() to the AlarmManager (both repeating alarm and a fixed alarm) but it seems that unless the device is charging any kind of repeating system has a variable repeat rate once the device is unplugged. Is there any way to run a stable consistently repeating service?
+2
A:
You do not want to do anything every minute, particularly when unplugged.
CommonsWare
2009-08-31 08:38:39
Are you saying it's impossible or just unadvised?
Brother Logic
2009-08-31 08:59:32
Strongly inadvisable. There was a Jeff Sharkey presentation on Google I/O, in which he explained that a simple service check every 5 minutes, exhausts as much battery, as the device staying idle for 5 minutes, which effectively cuts your battery life in half. My numbers may be a bit off, but it's somewhere along these lines.
Dimitar Dimitrov
2009-08-31 09:13:26
Yeah, I remember figures roughly like that as well. The presentation is online and highly recommended.
CommonsWare
2009-08-31 15:16:59
A:
Have you implemented Timer? It works very well for what I use it for, but then again I haven't worried about the precision at all. For all I know it may be varying a bit but I doubt it. It seems pretty consistent to me.
Edit: I am not liable for your responsible or irresponsible use of this facility ;)
MattC
2009-08-31 12:00:06