多線程與異步
Handler用來做什麼?
1、定時執行Message和MessageQueue;
2、在不同線程中執行Runnable。
Handler怎麼使用?
obtainMessage() //取得消息
sendMessage() //發送消息
handlerMessage() //處理消息
Message、 MessageQueue、Looper
Message 有2個整型數值 和 1個Object;
MessageQueue是Message的隊列
Looper消息泵
Looper的原理
如何使用:
1、是MessageQueue的管理者;
2、Looper.prepare()
3、每一個Looper對象和一個線程關聯
4、Looper.myLooper()可以獲得當前線程的Looper對象
Looper從MessageQueue中取出Message,交由Handler的handlerMessage進行處理;調用Message.recycle()將其放入Message Pool中。