2

I have 2 CountDownTimer objects in my app, that count the time to next event constantly as the app is running.

So today I debugged it, and found out that the timer is not accurate at all, I have given it an interval of 1 hour, starting at 9:00 am, and now 14:04 was when the next event fired. whole 4 mins late, and it is getting more and more with each event.

So should I use the CountDownTimer for such task, or I should just make an if check in it's onTick() method, where every second I will check for fixed time passed since the previous event, then reset the time for after 1 hour?

I can't do these tasks with AlarmManager, since all these things are happening in foreground service , and as much as I know, Alarms will be killed if the users swipes the app away from the running apps menu

jbutler483
  • 24,074
  • 9
  • 92
  • 145
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81
  • did you see [this?](http://stackoverflow.com/questions/4824068/how-come-millisuntilfinished-cannot-detect-exact-countdowntimer-intervals) - Q. Have you got this running on its own thread? or just on the main thread? – jbutler483 Nov 07 '14 at 12:41
  • CountDownTimer is very imprecise. Check this answer also: http://stackoverflow.com/a/6811744/2904294 – MadEqua Nov 07 '14 at 12:43
  • possible duplicate of [Android CountDownTimer shows 1 for two seconds](http://stackoverflow.com/questions/6810416/android-countdowntimer-shows-1-for-two-seconds) – jbutler483 Nov 07 '14 at 12:51

0 Answers0