new CountDownTimer(1000000, 1000) {
public void onTick(long millisUntilFinished) {
// Used for formatting digit to be in 2 digits only
NumberFormat f = new DecimalFormat("00");
long min = (millisUntilFinished / 60000) % 60;
long sec = (millisUntilFinished / 1000) % 60;
timer.setText("OTP Expires in: " f.format(min) ":" f.format(sec));
}
I am supposed to delete a OTP after the timer runs out which in this case is 10 minutes. I am not sure how to set the timer to 10 minutes.
CodePudding user response:
You can see it in CountDownTimer
new CountDownTimer(1000000, 1000) {
public void onTick(long millisUntilFinished) {
NumberFormat f = new DecimalFormat("00");
long min = (millisUntilFinished / 60000) % 60;
long sec = (millisUntilFinished / 1000) % 60;
}
public void onFinish() {
timer.setText("OTP Expires in: " f.format(min) ":" f.format(sec));
}
}.start();
CodePudding user response:
try this
new CountDownTimer(60*10*1000, 1000) {
public void onTick(long millisUntilFinished)
{
binding.time.setText("seconds remaining: "
millisUntilFinished / 1000);
}
public void onFinish() {
}
}.start();