Android學習筆記(十四) Handler理論補充

來源:互聯網
上載者:User

標籤:變數   handle   取出   message   queue   賦值   sdk   產生   read   

一、如何下載Android源碼

  在SDK Manager中選中Sources for Android SDK。

二、ThreadLocal初步介紹

  1)執行ThreadLocal對象(static final ThreadLocal sThreadLocal)的set(Object obj)方法,將會向存入一個以當前線程為鍵的索引值對。

  2)執行ThreadLocal對象的get()方法,將會根據當前線程對象為鍵,取出與之對應的值。

  在之前提到的Looper方法調用中:

  執行Looper.prepare時,系統會產生一個Looper對象,然後和當前線程通過ThreadLocal儲存(set)起來。產生Handler對象時,又根據線程名將Looper對象取(get)出來,然後賦值給Handler對象的mLooper成員變數。因此Looper和Handler的關係是通過ThreadLocal聯絡起來的。

  產生Looper對象時會產生一個與之相對應的MessageQueue對象。之後產生Handler對象時,將Looper對象和MessageQueue對象都賦值給Looper的成員變數。

Android學習筆記(十四) Handler理論補充

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.