Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 系列 4.7:發送與接收廣播訊息

編輯:關於 Android 程式設計

廣播訊息適合用於跨元件通知。接收端需要建立 BroadcastReceiver,並以 IntentFilter 指定有興趣的 action。

註冊與發送

可透過 Context.registerReceiver 註冊接收器,發送端則建立 Intent 並呼叫 sendBroadcast。若需要有序廣播,可使用 sendOrderedBroadcast。

執行環境注意事項

onReceive 通常在主執行緒被呼叫,適合短時間處理。若需要耗時工作,應轉交服務、JobIntentService 或其他背景機制。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved