CountDownTimer countdown is very simple and practical,
This is very simple, so the Code has nothing to explain. It is to remember this API.
Public class MainActivity extends AppCompatActivity {
Private TextView textView; private CountDownTimer downTimer; private long time = 100*1000; // The total countdown time ms @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); textView = (TextView) findViewById (R. id. tv1); initViews ();} private void initViews () {// 1000 indicates that onTick () downTimer = new CountDownTimer (time, 1000) is executed every 1000 ms) {@ Override public void onTick (long millisUntilFinished) {time-= 1000; textView. setText (time/1000 + "") ;}@ Override public void onFinish () {Toast. makeText (MainActivity. this, "ended", Toast. LENGTH_SHORT ). show () ;};} public void doClick (View view) {switch (view. getId () {case R. id. start: downTimer. start (); // start countdown break; case R. id. stop: downTimer. cancel (); // pause break ;}}