Count down timer in Android

Here is the easiest way to implement Count down in android.
this will show the timer in seconds only,
to get Timer in Minute and seconds 

Click here

CountDownTimer countDownTimer;
long duration = 300000;

countDownTimer = new CountDownTimer(duration, 1000)
 {
    public void onTick(long millisUntilFinished)
 {
txtTimer.setText("seconds remaining: "
+ millisUntilFinished / 1000);
    }

public void onFinish() {
txtTimer.setText("done!");
}
}.start();

if want to stop the timer before the finish time;


countDownTimer.cancel();

No comments:

Post a Comment