Android杂货摊:Handler-post和View-post的区别,android开发游戏加入时间限制

本文深入解析Android中View.post和Handler.post的区别。在View未attach到window时,View.post会将Runnable存储在HandlerActionQueue中,待View附加到窗口并分配Handler后,通过executeActions方法将Runnable放入消息队列执行。此过程涉及到View的attach过程和HandlerActionQueue的使用。
摘要由CSDN通过智能技术生成

}

// 仔细阅读下面这段注释!!!
// Postpone the runnable until we know on which thread it needs to run.
// Assume that the runnable will be successfully placed after attach.
getRunQueue().post(action);
return true;
}

从上面的源码,我们大概可以看出mAttachInfo字段在这里比较关键,当其有值时,其实和普通的Handler.post就没区别了,但
有时它是没值的,比如我们上面示例代码里的onCreate阶段,那么这时执行到了getRunQueue().post(action);这行代码,从这段注释也大概可以看出来真正的执行会被延迟(这里的Postpone注释);我们接着往下看看getRunQueue相关的代码,如下:

/** 其实这段注释已经说的很清楚明了了!!!

  • Queue of pending runnables. Used to postpone calls to post() until this
  • view is attached and has a handler.
    */
    private HandlerActionQueue mRunQueue;

private HandlerActionQueue getRun

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值