From my observation the android CountDownTimer countDownInterval between ticks happens to be not accurate, the countDownInterval is regularly a few milliseconds longer than specified. The countDownInterval in my specific app is 1000ms, just counting down a certain amount of time with one second steps.
Due to this prolonged ticks I end up having less ticks then wanted when the the countdowntimer runs long enough which screws up the displayed countdown of the time (a 2 second step happens on the UI level when enough additional ms have summed up)
Looking into the source of CountDownTimer it seems possible to twist it so it corrects this unwanted inaccuracy yet I was wondering if there is already a better CountDownTimer available in the java/android world.
Thanks buddies for any pointer …
Rewrite
As you said, you also noticed that the next time in
onTick()is calculated from the time the previousonTick()ran, which introduces a tiny error on every tick. I changed the CountDownTimer source code to call eachonTick()at the specified intervals from the start time.I build this upon the CountDownTimer framework, so cut & paste the source code into your project and give the class a unique name. (I called mine MoreAccurateTimer.) Now make a few changes:
Add a new class variable:
Change
start():Change the Handler’s
handlerMessage():