class H extends Handler {
}
这里实现的是Handle的一个方法,子类overwrite这个类
public void handleMessage(Message msg)这个方法的入参是Message这个参数,
根据msg.what这个参数的常量进行解析,接着看,这个方法在什么时间被调用?
通过hanlde这个类的方法调用的,这个方法是dispatchMessage,入参也是Message,先检测msg的callback是否存在?然后判断handle的callback是否存在,如果都存在就执行handleMessage这个方法。
dispatchMessage方法怎么触发呢?
通过触发的方式知道:执行的是msg的target属性对象,该对象的dispatch Messge方法
msg:Mesage,这个msg和handle里面是同一个对象,都是Message类
在这里感觉有点绕了,为什么Message里有Handle,handle又处理Message呢?这里是不是存在循环依赖了?
Message这个类是干嘛用呢?
Defines a message containing a description and arbitrary data object that can be sent to a Handler. This object contains two extra int fields and an extra object field that allow you to not do allocations in many cases.
While the constructor of Message is public, the best way to get one of these is to call Message.obtain() or one of the Handler.obtainMessage() methods, which will pull them from a pool of recycled objects.
通过翻译可以看到,这个Message是传递消息的,并且不建议开发自己通过new的方式创建message,最好的方式是Message.obtain()的方式拿到一个对象
这个类有如下4个属性,分别是消息ID、消息内容、处理这个消息的handler
通过拿到这个消息后,就可以进行消息的处理和分发了,
另外一个疑问,这个handler是设么事件设置给message呢?
Choreographer
消息队列的入栈内容和顺序
添加的消息会放在队尾部进行执行