抛出问题
当一个Handler创建之后设置发送延迟消息,在这个期间,修改手机的系统时间,会影响该延迟消息的发送时机吗?
【探究】修改系统时间对Handler延迟消息有无影响?
首先锁定【Handler源码】:
public final boolean postDelayed(Runnable r, long delayMillis)
{
return sendMessageDelayed(getPostMessage(r), delayMillis);
}
然后锁定该方法:
public final boolean sendMessageDelayed(Message msg, long delayMillis)
{
if (delayMillis < 0) {
delayMillis = 0;
}
return sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis);
}
随后锁定该方法:
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
MessageQueue queue = mQueue;
if (queue == null) {
RuntimeException e = new RuntimeException(
this + " sendMessageAtTime() called with no mQueue");
Log.w("Looper", e.getMessage(), e);
return false;
}
return enqueueMessage(queue, msg, uptimeMillis);
}
最后锁定该方法:
private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
msg.target = this;
if (mAsynchronous) {
msg.setAsynchronous(true);
}
return queue.enqueueMessage(msg, uptimeMillis);
}
着重:
sendMessageAtTime(msg, SystemClock.uptimeMillis() + delayMillis);
/**
* Returns milliseconds since boot, not counting time spent in deep sleep.
*
* @return milliseconds of non-sleep uptime since boot.
/**
* 返回启动后的毫秒数,不计算深度睡眠时间。
*
* @return 自启动以来非睡眠正常运行时间的毫秒数。
*/
*/
@CriticalNative
native public static long uptimeMillis();
网友评论