Ok,I need to create an infinite loop on a countdown. My code is:
public void countdown() {
if (x != null) {
x.cancel();
}
x = new CountDownTimer(20000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
showNotification();
}
};
x.start();
}
x is just a static countdowntimer variable. The problem is that I tried many methods to make the above code work,I mean when the countdown ends,and it displays that notification,it should start again and so on....but I can't find a way to do it.
is to restart your timer when his has finished :) like this :
Hope this will help you.
Why not just use a regular Timer? It will repeat on a specified interval until you call cancel(), something like:
Simple way to create an infinite loop:
Every one secod call method
to keep your timer working just put
in the
onfinish
blockFor the record CountDownTimer(long millisInFuture, long countDownInterval)
Where Long.MAX_VALUE = 9223372036854775807 miliseconds or around 292 million of years (seconds more or less)
Its not infinite but its incredibly long.