In my android application, i am running a remote service which is started in the foreground
startForeground(1, notification)
so that it is not killed. In this service a task is allowed to run every 15 minutes like this and repeated.
handler.post(scheduledTask);
class ScheduledTask implements Runnable{
@Override
public void run() {
// Do the task
// Repeat the task after the interval
handler.postDelayed(this,INTERVAL);
}
}
I kept this application on for a day. But after midnight, it stopped working for a like around 5-6 hours and then early mornign when i resumed the application, it continued.
Could someone tell me what could have caused this issue ? I tested this in a Galaxy Note.
Use AlarmManager better than a postDelayed. I can’t post code right now, but I had the same needs and AlarmManager proved to be much better than postDelayed.
You’ll need some kind of alarm receiver (BroadcastReceiver, for example) that will start your Service every time the Alarm event (an Intent) occurs.