I want to restart countdown timer with new time when countdown timer finishes. I am giving code below:
futureInMillis = newTime();
CountDownTimer remainingTimeCounter = new CountDownTimer(futureInMillis, 1000) {
public void onTick(long millisUntilFinished) {
remainingTime = calculateRemainingTime(millisUntilFinished / 1000);
runOnUiThread(updateTime);
}
public void onFinish() {
// TODO: restart counter
cancel();
futureInMillis = newTime();
// remainingTimeCounter = null;
this.start();
}
}.start();
we should know what the
newTime()
do , and you don't have to call the methodcancel()
, because the timer is in theonFinish()
method , that's means that the timer is finished counting down :EDIT :
there is no attribut in the class
CountDownTimer
to use in order to change the futureInMillis , if you want to use that , you should use twoCountDownTimer
; you should create two classes , each class has a timer and an attribut of futureInMillis , and then when the timer of the first Class finished, instanciate the second class , pass the futureInMillis to it , and start her timer, and vice versa .Or simply Edit the code source of the class CountDownTimer from the source code android and add setters and getters for attributs futureInMillis like this :
and then you can change the millisInFuture easily like this :