One very basic way to loop a CountDownTimer is to call start()
in onFinished()
.
public void onFinish() {
...
start(); // Start this timer over
}
(Make sure you cancel your CountDownTimer in onPause()
when you do this otherwise the timer might leak and keep firing in the background... Oops.)
However CountDownTimers has fundamental flaws (in my opinion): it often skips the last call to onTick()
and it gains a few milliseconds each time onTick()
is called... :( I re-wrote CountDownTimer in a previous question to be more accurate and call every tick.