Timer appears to be pausing when screen becomes inactive
Posted
by elchuppa
on Stack Overflow
See other posts from Stack Overflow
or by elchuppa
Published on 2010-03-20T14:29:12Z
Indexed on
2010/03/20
14:31 UTC
Read the original article
Hit count: 242
android
So I have a very simple android activity that starts a timer when you hit a button.
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
doStuff();
}
}, 15 * 60 * 1000);
So this worked reasonably well for me when I was testing but as it turns out when the screen becomes inactive so does the timer. I was a bit surprised by this. I understand you need to create a service to have anything running in the background but I hadn't realized this is required for an activity in the foreground when the phone has inactivated the screen due to lack of activity. What confuses me is I think this worked as I expected originally and just in the last few weeks or so has the timer been affected by the phone saving power. I could be wrong though..
So basically my questions are: am I seeing expected behavior? Do I need to create all timers as services or somehow disallow powersaving?
thanks for any advice, Patrick
© Stack Overflow or respective owner