MauroAlexandro
MauroAlexandro

Reputation: 367

What's the best way to make a Count Down Timer?

I am wondering if this is the best way to make a timer of 1 minute on Android:

 new CountDownTimer(60000, 1000) {

            public void onTick(long millisUntilFinished) {

            }

            public void onFinish() {

            }

        }.start();

Upvotes: 0

Views: 89

Answers (2)

Ben-J
Ben-J

Reputation: 1125

You don't need to use the onTick():

new CountDownTimer(60000, 60000) {

    public void onTick(long millisUntilFinished) {

    }

    public void onFinish() {
        //do your stuff here
    }

}.start();

Upvotes: 1

Bajirao Shinde
Bajirao Shinde

Reputation: 1354

This is the easy and very simple way

new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

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

for more info see this link

Upvotes: 1

Related Questions