Joke Collection Website - Blessing messages - Android uses service and CountDownTimer to implement a countdown timer function?

Android uses service and CountDownTimer to implement a countdown timer function?

When we usually program, we often use the countdown function. Many people don’t know that Android has encapsulated a class for it, so they often write it themselves. Now that I have discovered this class, please share it with me:

Continuously display the remaining time in a TextView, the code is as follows:

[java] view plaincopy

< p>private TextView vertifyView;

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

@Override

public void onTick(long millisUntilFinished) { < /p>

vertifyView.setText((millisUntilFinished / 1000) + "Can be resent after seconds");

}

@Override

public void onFinish() {

vertifyView.setEnabled(true);

vertifyView.setText("Get verification code");

}

< p> };

The call is very simple: timer.start();

Finally, the first parameter in CountDownTimer timer = new CountDownTimer(10000, 1000) Represents the total time, and the second parameter represents the interval time. This means that the onTick method will be called back every second, and then the onFinish method will be called back 10 seconds later.