Android CountDownTimer

2019-02-17 05:20发布

When writing :

 CountDownTimer timer = new CountDownTimer(1000, 100) 
 {
      @Override
       public void onTick(long l) 
       {

       }

       @Override
       public void onFinish() 
       {

       };
 }.start();

are we actually starting a new thread that handles ticks? If not, what is really happening?

2条回答
老娘就宠你
2楼-- · 2019-02-17 06:11

Definition from multiple publications, tried and tested:

"Another timer is provided with the built-in class CountDownTimer.This encapsulates the creation of a background thread and the handler queuing into a convenient class call..."

查看更多
贼婆χ
3楼-- · 2019-02-17 06:17

CountDownTimer's implementation uses Handler and sendMessageDelayed(), so no background thread is needed. This does mean that the timer will not update if you are tying up the main application thread elsewhere in your code.

查看更多
登录 后发表回答