Android CountDownTimer
Asked Answered
T

2

6

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?

Touchwood answered 22/4, 2010 at 13:10 Comment(0)
P
11

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.

Paratuberculosis answered 22/4, 2010 at 14:7 Comment(0)
A
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..."

Amboceptor answered 23/8, 2011 at 13:9 Comment(1)
There is no background thread created, look at the implementation.Libertinism

© 2022 - 2024 — McMap. All rights reserved.