工作筆記 11


開始使用 工作區域去多屏幕切換
linux super+s
win10 開啓 Win + Ctrl + D  關閉Win + Ctrl + F4  切換 Win + Ctrl + D +左/右
win tab 顯示所有任務欄、工作區

Android中 
android只允許一個線程繪製UI。比如在activity的oncreate方法中沉睡了線程則會影響了 ui繪圖時間
UI 操作通常會通過投遞消息來實現,只有往正確的 Looper 投遞消息才能得到處理,實現繪圖,對於 UI 來說,這個 Looper 一定是運行在 UI 線程中。
消息需要在 Looper 中處理,Looper 又需運行在 Thread 中,所以不能隨隨便便在非 UI 線程中進行 UI 操作。

在哪個線程創建Handler 就使用那個線程的looper

作爲所有控件基類的 view 提供了 post 方法,用於向 UI Thread 發送消息,並在 UI Thread 的 Looper 中處理這些消息,而 UI Thread  一定有 Looper 這是由 ActivityThread 來保證的:
    public final class ActivityThread {  
    ...  
        final Looper mLooper = Looper.myLooper();  
    }  

在我們寫的main ACtivity中 會在此開闢一個真正的UI線程 ActivityThread (真正的UI線程,重要性也不言而喻)

在其中生成了 mLooper 
final Looper mLooper = Looper.myLooper();  且在activity源碼中使用到了 Looper.myLooper() != mMainThread.getLooper();
最後 ActivityThread.java 的 main() 方法 中進行了   Looper.loop();  循環。

猜測: 對於不同activity來講 所使用的ActivityThread是同一個,ActivityThread是單例,

完整流程
ActivityThread 定義了 looper ------view父類使用這個looper,創建了mHandler,post了消息  return attachInfo.mHandler.post(action);
最後----ActivityThread,做了loop()循環,在loop()循環中更新了試圖。

 Android實戰簡易教程-第六十七槍(android動畫實現窗口抖動效果) 
view 20992行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章