Android的CountDownTimerAndroid、CountDownTimer

2023-09-06 15:46:17 作者:气势

当写:

 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?

推荐答案

CountDownTimer 的implementation使用处理程序 sendMessageDelayed(),所以没有后台线程是必要的。这也意味着,如果你在你的code占用主应用程序线程在其他地方的计时器将不会更新。

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.