Reputation: 61
I want to create a custom countdown timer in Android Studio but I want it to have a longer duration/interval between 2 counts rather than a normal countdown timer. Please help me out.
Upvotes: 1
Views: 2158
Reputation: 22832
By setting the countDownInterval argument, you can change the interval between two ticks:
private CountDownTimer mCountDownTimer = new CountDownTimer(millisInFuture, countDownInterval) {
public void onTick(long millisUntilFinished) {
// do sth here...
}
public void onFinish() {
// do sth here...
}
};
For example by setting it to 2000, the timer ticks every 2 seconds. To start or stop timer:
mCountDownTimer.start();
mCountDownTimer.cancel();
Upvotes: 1
Reputation: 13539
You could try this:
new CountDownTimer(30000, 1000) {//initial interval is one second
private int i = 0;
public void onTick(long millisUntilFinished) {
i++;
if (i % 2 == 0) {//if you want a longer interval to do something
//practical interval is now two seconds, change as you want.
......
}
}
public void onFinish() {
.....
}
}.start();
Upvotes: 1