IntentService源碼分析

實現思路

  • thread + handler
  • 暴露唯一接口onHandleIntent給子類實現
  • 消息隊列保證任務的順序性
  • 巧妙的自動退出機制,其關鍵點
    • stopSelf(int startId), Stop the service if the most recent time it was started was <var>startId</var>.
    • onStartCommand(Intent intent, int flags, int startId), startId is A unique integer representing this specific request to start. Use with {@link #stopSelfResult(int)}.
發佈了113 篇原創文章 · 獲贊 6 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章