Why does CountDown Timer in Android use a handler?

The GrepCode countdown timer indicates that it uses a handler. Is there any specific reason for using handlers? Because handlers are commonly used when we interact with the user using threads. But there are no threads that I can see in the countdown timer. And also the countdown timer works when using the user interface in the stream itself.

+2
source share
3 answers

Since handlers are commonly used when we interact with the user using threads

True. ""!= "".

, Handler , postDelayed() sendMessageDelayed(), CountDownTimer. . , , , , Timer TimerTask.

, .

Handler Looper. CountDownTimer, , , , HandlerThread.

+3

.

, , , , , onTick() . , , , onfinish().

+1

You can use a handler not only for communication between threads. The handler was able to execute some code after a certain time (postDelayed function). On Android OS Handler, the preferred tool (instead of java Timer) is for use if you need to execute some code after a time interval. In the countdown timer, the handler is used to configure the code at intervals of one second.

+1
source

All Articles