Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CountDownTimer

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?

like image 831
rantravee Avatar asked Apr 22 '10 13:04

rantravee


2 Answers

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.

like image 124
CommonsWare Avatar answered Oct 14 '22 12:10

CommonsWare


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

like image 2
antbkr Avatar answered Oct 14 '22 12:10

antbkr