Android消息机制
2021-04-21 15:09:38 4 举报
Handler、Message、Looper、HandlerThread关系描述。
作者其他创作
大纲/内容
HandlerThread
- mLooper:Looper
+ run()+ getLooper():Looper
Handler
- mLooper:Looper- mQueue:MessageQueue- mCallback:Callback
+ obtainMessage():Message+ sendMessage()+ post()+ handleMessage()+ distpatchMessage()
+ obtainMessage():Message+ sendMessage()+ post()+ handleMessage()+ distpatchMessage()
Handler::dispatchMessage(msg) { if (msg.callback != null) { handleCallback(msg); } else { if (mCallback != null) { if (mCallback.handleMessage(msg)) { return; } } handleMessage(msg); }}
MessageQueue
~ mMessages:Message
+ enqueueMessage()+ next():Message
Message
~ target:Handler~ next:Message
+ obtain():Message
HandlerThread::run() { Looper::loop() { for (;;) { MessageQueue::next(); Message.target::distpatchMessage() { Handler::handleMessage() } } }}
Looper
+ mThread:Tread+ mQueue:MessageQueue
+ loop()+ getThread():Thread+ getQueue():MessageQueue
0 条评论
下一页