skip to Main Content
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.

2

Answers


  1. 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();
    
     
    
    Login or Signup to reply.
  2. try this

        new CountDownTimer(60*10*1000, 1000) {
    
            public void onTick(long millisUntilFinished)
            {
                binding.time.setText("seconds remaining: "
                        + millisUntilFinished / 1000);
    
            }
    
            public void onFinish() {
    
            }
        }.start();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search