Timer in android not correctly repeating on delay
I have this code called in a Service:
timer.scheduleAtFixedRate(new TimerTask(){
public void run() {
showNotification();
}
}, firstNotify, 86400000L);
It is my understanding that this should cause showNotification()
to be called once per day at the same time each day, at the time specified in firstNotify (86400000 being the milliseconds in a day).
However, the noti开发者_运维知识库fies were happening approximately every 3 hours on my phone, and a little over 4 hours on my friend's phone. Is there any reason why these would be occurring faster than the specified 1-day period for repeating?
I know its not a direct answer to your question, but you should use AlarmManager
in such cases as yours. See setRepeating
function.
If your Service
is not setup correctly and it is being shut down at some point, the Timer would be recreated and called again after a firstNotify
delay. Does this sound possible? You might be better off using AlarmManager
to create the timed event.
精彩评论