Handler
創(chuàng)建handler主要有兩個(gè)構(gòu)造玻淑,一個(gè)無(wú)參一個(gè)需要一個(gè)Looper
無(wú)參構(gòu)造就會(huì)使用MainLooper
所以Handler中肯定有一個(gè)Looper
使用handler發(fā)送消息時(shí)
handler會(huì)把自己保存在Message中
然后把Message給Looper的MessageQueue
Looper會(huì)循環(huán)從MessageQueue中取出Message
調(diào)用Message中帶的Handler方法來(lái)處理該消息
Looper會(huì)在線程中死循環(huán),直到從MessageQueue中拿到一個(gè)空消息
Handler在哪個(gè)線程執(zhí)行呀伙,取決于Looper屬于哪個(gè)線程
每個(gè)線程只能有一個(gè)Looper
每個(gè)Looper只能有一個(gè)MessageQueue
可以多個(gè)handler共用一個(gè)Looper