Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • CountDownTimer in Android

    • 0
    • 2
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 558
    Comment on it

    CountDownTimer is an abstract class available in android. This class contains two abstract method i.e. onTick(long) and onFinish().

    onTick(long millisUntilFinished): Callback fired on regular interval.
    onFinish()                      : Callback fired when the time is up.
    

    This class schedule a countdown until a time in the future, with regular notifications on intervals along the way.
    An Example of CountDownTimer class showing a 30 second countdown in a text field:-
    Declare a two long constant:-

    private final long TOTAL_DURATION = 30000, COUNT_INTERVAL = 1000;
    

    Now in the onCreate() method:-

     new CountDownTimer(TOTAL_DURATION, COUNT_INTERVAL) {
    
            public void onTick(long millisUntilFinished) {
                 timerTextView.setText("seconds remaining: " + millisUntilFinished / 1000);
            }
    
            public void onFinish() {
                  timerTextView.setText("done!");
             }
      }.start();
    

    Your 30 seconds CountDown is ready.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: