public final boolean postDelayed(Runnable r, long delayMillis)
看英文文档 没看明白。。。
求解释
Causes the Runnable r to be added to the message queue, to be run
* after the specified amount of time elapses.
(前后的懂,下面这句就悲催了)
* The runnable will be run on the thread to which this handler
* is attached.
==========
网上说 每 delayMillis 执行一次, 为啥我测试一下 只执行一次?
这是为啥?
=========================
还有哪位明白人顺便把post 等该方法中的postAtTime等其他方法也解释一下
不胜感激
------最佳解决方案--------------------
postDelayed(Runnable r, long delayMillis)
延时delayMillis毫秒 将Runnable插入消息列队,
Runnable将在handle绑定的线程中运行。
post 是立即插入消息列队,当消息列队处理到该消息时才运行
------其他解决方案--------------------
个人见解:
The runnable will be run on the thread to which this handler is attached.
这句话的意思是这个接口将会在线程绑定的handler上运行,就是说你的handler绑定哪个线程,就延迟哪个线程
------其他解决方案--------------------
public final boolean postDelayed(Runnable r, long delayMillis)
从当前时间开始延迟delayMillis时间后执行Runnable,只执行一次
public final boolean postAtTime(Runnable r,long uptimeMillis)
在指定的有效时间内执行并且完成Runnable
源码在对此方法的返回值有个提醒:
usually because the looper processing the message queue is exiting.
Note that a
result of true does not mean the Runnable will be processed -- if
the looper is quit before the delivery time of the message
occurs then the message will be dropped.
大概意思是说结果返回true不一定就意味着执行完成了Runnable,比如-如果looper在小于uptimeMillis的时间内退出的话,消息将会被停止
------其他解决方案--------------------
LZ查看下 Handle和 Message之间的关系就了解了
Handler实际上就是个定时器,与Timer差不多,主要维护了一个消息队列MessageQueue
------其他解决方案--------------------
你测试对了,就是只执行一次。
------其他解决方案--------------------
The runnable will be run on the thread
runnable将会在一个线程中运行
什么样的线程的?
to which this handler is attached即:
this handler is attached to the thread
有handler附属的一个线程,随便翻译的
------其他解决方案--------------------
听楼上几位这么一解释 我好像是明白了点
------其他解决方案--------------------
忙了一下午,下班回家结贴
------其他解决方案--------------------
好吧, 先这样, 谢谢大家
------其他解决方案--------------------