Implementing counter in Android

前端 未结 2 1208
终归单人心
终归单人心 2021-01-07 07:05

I have got an application where I need to show counter from 3 to 1 then quickly switch to another activity. Will TimerTask will be suitable for doing this? Can anybody show

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-07 07:26

    I would better use a CountDownTimer.

    If you want for example your counter to count 3 seconds:

    //new Counter that counts 3000 ms with a tick each 1000 ms
    CountDownTimer myCountDown = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            //update the UI with the new count
        }
    
        public void onFinish() {
            //start the activity
       }
    };
    //start the countDown
    myCountDown.start();
    

提交回复
热议问题