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.
Since handlers are commonly used when we interact with the user using threads
True. ""!= "".
, Handler , postDelayed() sendMessageDelayed(), CountDownTimer. . , , , , Timer TimerTask.
Handler
postDelayed()
sendMessageDelayed()
CountDownTimer
Timer
TimerTask
, .
Handler Looper. CountDownTimer, , , , HandlerThread.
Looper
HandlerThread
.
, , , , , onTick() . , , , onfinish().
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.