当前位置: 首页 > news >正文

北京 工业网站建设公司教程网

北京 工业网站建设公司,教程网,网站开发技术题目,微信营销软件免费版1.前提 前面说到sendMessage携带的delay会被加上SystemClock.uptimeMillis() ,最终赋值给Message的when。 msg.when SystemClock.uptimeMillis() delayMillis; 那么when除了用来在链表里面作为排序依据以外,还在哪里用到了呢? 2.Looper…

1.前提

前面说到sendMessage携带的delay会被加上SystemClock.uptimeMillis() ,最终赋值给Message的when。

msg.when = SystemClock.uptimeMillis() + delayMillis;

那么when除了用来在链表里面作为排序依据以外,还在哪里用到了呢?

2.Looper.loop

首先看下Looper的loop里面,循环取queue的msg,如果msg为null,返回;否则执行msg

public final class Looper {public static void loop() {final Looper me = myLooper();final MessageQueue queue = me.mQueue;for (;;) {Message msg = queue.next(); // might block  获得下一个消息if (msg == null) {// No message indicates that the message queue is quitting.return;}msg.target.dispatchMessage(msg); //执行Messagemsg.recycleUnchecked(); //msg放入缓存}}
}

3.MessageQueue.next

看下queue.next()的实现,会通过when计算下一条消息需要等待的时长。

nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE); 

public final class MessageQueue {Message next() {// Return here if the message loop has already quit and been disposed.// This can happen if the application tries to restart a looper after quit// which is not supported.final long ptr = mPtr;if (ptr == 0) {return null;}int pendingIdleHandlerCount = -1; // -1 only during first iterationint nextPollTimeoutMillis = 0; //下一条消息等待的时长for (;;) {if (nextPollTimeoutMillis != 0) {Binder.flushPendingCommands();}//等待nextPollTimeoutMillis,不往下执行nativePollOnce(ptr, nextPollTimeoutMillis);//时间到了synchronized (this) {// Try to retrieve the next message.  Return if found.final long now = SystemClock.uptimeMillis();Message prevMsg = null;Message msg = mMessages;if (msg != null) {if (now < msg.when) { //当前时间小于when// Next message is not ready.  Set a timeout to wake up when it is ready.nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE); //等待时长} else {// Got a message.mBlocked = false;if (prevMsg != null) {prevMsg.next = msg.next;//将msg从链表中移除} else {mMessages = msg.next; //更新表头}msg.next = null;msg.markInUse();return msg;}} else {// No more messages.nextPollTimeoutMillis = -1;}                }// Run the idle handlers.// We only ever reach this code block during the first iteration.for (int i = 0; i < pendingIdleHandlerCount; i++) {final IdleHandler idler = mPendingIdleHandlers[i];mPendingIdleHandlers[i] = null; // release the reference to the handlerboolean keep = false;try {keep = idler.queueIdle();} catch (Throwable t) {Log.wtf(TAG, "IdleHandler threw exception", t);}if (!keep) {synchronized (this) {mIdleHandlers.remove(idler);}}}// Reset the idle handler count to 0 so we do not run them again.pendingIdleHandlerCount = 0;// While calling an idle handler, a new message could have been delivered// so go back and look again for a pending message without waiting.nextPollTimeoutMillis = 0;}}
}

http://www.yayakq.cn/news/357580/

相关文章:

  • 云南建设厅网站安全处网站策划建设方法
  • 淮安新网站制作网络维护工程师工资多少
  • 创建网站有什么用南通住房和城乡建设部网站首页
  • 网站的域名做邮箱吗免费建立小程序网站
  • 怎么做代刷网站长网站防采集
  • 网站开发 模块电商网站收费吗
  • 网站建设的单可以刷吗wordpress网站地图自动更新
  • 网站网站如何做的充值有没有会计做兼职的网站
  • jq网站特效插件网站首页 模板
  • 杭州做网站的优质公司制作网站需要哪些技术
  • 安阳企业建网站北京做网站哪家好
  • 网站制作软件小学58同城 网站建设 成都
  • 做珠宝首饰网站美食网站案例
  • 深圳网站商城定制设计开发的某网站建设公司网站源码
  • 本科 网站建设的基础教程wordpress做社区
  • 佛山企业网站建设策划专业门户网站的规划与建设
  • 珠海建网站价格wordpress模板制作教程下载
  • 电脑网站做淘宝客怎么做整人的网站
  • 企业网站的作用有哪些wordpress分页 权重
  • 淮安哪里有做网站的人做视频网站视频短片
  • wordpress模板网站导航响应式网站导航栏模板
  • 个人营销型网站好看的手机网站推荐
  • 网站建设招标评分表网站有做货
  • 花都网站建设网页设计asp网站ftp入侵
  • 中国工厂网站网络搭建drc
  • 做英文网站的标准字体网站源码查看
  • 做网站线稿软件有哪些长久新开传奇网站
  • 哈尔滨网站建设nsstd做logo专用的网站是哪个
  • 网站建设 2018网站怎么做短信营销
  • 陵水网站建设报价织梦后台点击网站主页