的倒计时器表明,它采用了处理程序。有没有使用任何处理具体的原因?因为当我们正在做使用线程的一些用户交互处理程序一般都采用。但这里有没有线程,我可以在倒数计时器看到的。而且在UI线程它自身使用时,倒数计时器工作。
解决方案由于我们正在做使用线程的一些用户交互处理程序一般都是用
真。然而,一般!=总是。
恰巧处理程序
有计时的目的,如 postDelayed()
和 sendMessageDelayed(),其中 CountDownTimer
需要的优势。您可以使用那些自己为好。他们是很好的和轻量级的,因为,当你注意,我们并不需要一个单独的线程,事物的方式像定时
和的TimerTask
做的。
和也是在UI线程它自身使用时,倒数计时器工作。
它需要一个线程带有附加尺蠖
使用处理程序
。 CountDownTimer
可能是一般的主应用程序线程的使用,如果不说,在一些单独的 HandlerThread
。
The GrepCode of count down timer shows that it uses a Handler. Is there any specific reason for using handlers? Because handlers are generally used when we are doing some user interaction using threads. But here there are no threads that I can see in Countdown Timer. And also Countdown Timer works when used in the UI thread it self.
解决方案Because handlers are generally used when we are doing some user interaction using threads
True. However, "generally" != "always".
It so happens that Handler
has useful methods for timing purposes, like postDelayed()
and sendMessageDelayed()
, which CountDownTimer
takes advantage of. You can use those yourself as well. They are nice and lightweight because, as you note, we do not need a separate thread, the way things like Timer
and TimerTask
do.
And also Countdown Timer works when used in the UI thread it self.
It needs a thread with an attached Looper
to use Handler
. CountDownTimer
is probably usually used on the main application thread, and if not that, on some separate HandlerThread
.
上一篇:SPINNER过滤XML数据已被检索已被、数据、SPINNER、XML
下一篇:安卓java.lang.IllegalMonitorStateException:等待对象之前没有锁定的线程()线程、对象、java、lang