Android CountDownTimer

狂风中的少年 提交于 2019-12-19 07:10:25

问题


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?


回答1:


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.




回答2:


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..."



来源:https://stackoverflow.com/questions/2691026/android-countdowntimer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!