一个Activity多个Handler时,Message是如何传递的(个人总结)


作者:海岸线-haianxian 
来源:CSDN 
原文:https://blog.csdn.net/u010680097/article/details/52142396 
版权声明:本文为博主原创文章,转载请附上博文链接!

上面是作者的原文,看完后个人总结最重要的底层代码:

private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
    msg.target = this;
    if (mAsynchronous) {
        msg.setAsynchronous(true);
    }
    return queue.enqueueMessage(msg, uptimeMillis);
}
--------------------- 
作者:海岸线-haianxian 
来源:CSDN 
原文:https://blog.csdn.net/u010680097/article/details/52142396 
版权声明:本文为博主原创文章,转载请附上博文链接!

         msg.target = this  ,这一句是重点,当我们写源代码比如:

handler.sendEmptyMessage(8);

       当执行msg.target后,就会使handler作为msg的target属性的值,赋给msg信息,然后将这条信息放到消息队列中了,这样就标识了handler和msg的关系
 

猜你喜欢

转载自blog.csdn.net/Crystal_xing/article/details/84858568