Friday, 6 September 2013

Timertask stopping when screen locks

Timertask stopping when screen locks

I'm using timer task to send updates on my API. The problem is, when the
device is inactive, I don't really know the exact state. The timertask
stops. Then when I unlock the screen and navigate again, the task started
again.
Here's how I do it:
myTimer = new Timer();
UpdateCurrentLocation updateCurrentLocation= new UpdateCurrentLocation();
myTimer.scheduleAtFixedRate(updateCurrentLocation, 0, 900000);
This is updating every 15 minutes. But the activity stops when the device
is disabled. I want updateCurrenLocation to be executed every 15 minutes
even on background or the device is locked or even the app is not on the
front.
Any ideas? Thanks!

No comments:

Post a Comment