Android 的消息机制
2021-06-01 12:00:37 0 举报
Android 的消息机制
作者其他创作
大纲/内容
构建一个 looper 并放到线域里面
MessageQueue
Looper.loop()
Looper me = myLooper()从 sThreadLocal 中取出当前线程的 looper
Looper
mQueue = mLooper.mQueue
Handler
- Looper mLooper- MessageQueue mQueue
handleMessage
从消息队列中取出消息
for 循环里面会不断的从消息队列中取消息;msg.target 就是 handler
MessgeQueue.next
mLooper = Looper.myLooper()
mQueue = new MessageQueue(...)
Handler handler = new Handler()
handler.dispatchMessage(msg)
sThreadLocal.put(looper)
Looper
- MessageQueue mQueue- ThreadLocal sThreadLocal- Thread mThread
sendMessage
mThread = Thread.currentThread()
Looper.prepare()
handler.handleMassage(msg)
new Looper(...)
MessageQueue queue = me.mQueuefor(; ;){ Message msg = queue.next() msg.target.dispatchMessage(msg)}
0 条评论
回复 删除
下一页