Android Handler官方說明

來源:互聯網
上載者:User

標籤:訊息傳遞   不同   綁定   http   官方   hand   mes   time   tde   

官方API文檔:https://developer.android.google.cn/reference/android/os/Handler

Handler允許您發送和處理與線程的MessageQueue關聯的Message和Runnable對象。每個Handler執行個體都與單個線程和該線程的訊息佇列相關聯。當建立一個新的Handler對象時,它將被綁定到建立他的線程和線程的訊息佇列,然後Handler將訊息傳遞並添加到訊息佇列,並在訊息佇列中處理並執行它們。

Handler有兩個主要的功能:

  • 安排訊息或Runnable在某個主線程中某個地方執行;
  • 安排一個動作在不同的線程中執行。

調度訊息的方法包括有:

post(Runnable r)  將Runnable對象r添加到訊息佇列中
postAtTime(Runnable r, long uptimeMillis)  將Runnable對象r添加到訊息佇列中,並在uptimeMillis設定的時間執行
postDelayed(Runnable r, long delayMillis)  將Runnable對象r添加到訊息佇列中,並延時delayMillis後執行
sendEmptyMessage(int what)  發送空訊息,只包含what屬性
sendMessage(Message msg)  將訊息添加到正在等待的訊息的隊列末尾
sendMessageAtTime(Message msg, long uptimeMillis)  在指定的時間uptimeMillis將訊息添加到正在等待的訊息的隊列末尾
sendMessageDelayed(Message, long)  在延時delayMillis後將訊息添加到正在等待的訊息的隊列末尾

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.