• Have Any Question?
  • contact@eitworld.com

Count Down Timer





A Count Down Timer is a timer that runs in reverse. It starts the counting from the time specified to it and does reverse counting with the steps that are also specified to it. And finally it ends on 0. Count down timer can be used to display a timer for a particular task. It can also be used to provide a delay between two tasks.

Step 1- Object of class CountDownTimer is used to create a timer.

CountDownTimer timer=new CountDownTimer(10000, 1000) {
}

The constructor takes two arguments-

    • Total time- It is the total time in milliseconds.
    • Interval- It is the interval time in milliseconds. Interval time means the time after which one tick will occur.
    • Step 2- Two methods inside it are important-

 

    • onTick(long)- This method contains the code that will be executed everytime the timer is ticked. It takes one long type argument, which is the time at the time of the tick in milleseconds.
    • onFinish()- This method will contain the code that will be executed when the timer has finished counting.
    • Step 3- Don’t forget to start the timer after creating it.

 

timer.start();

So finally the code becomes-

CountDownTimer timer=new CountDownTimer(10000, 1000) {

@Override

public void onTick(long ticktime) {

// TODO Auto-generated method stub

}

@Override

public void onFinish() {

// TODO Auto-generated method stub

}

};

timer.start();



Real Time Web Analytics