IntentService將使用隊列管理請求Intent,每當客戶端通過Intent啓動IntentService時,IntentService將會由該Intent加入到隊列中,開啓新的線程來處理該Intent。
對於異步的startService()請求,IntentService會處理Intent,該線程同一時刻處理一個Intent。
因此不會阻塞主線程。
Intentservice具有如下特徵:
1.IntentService會創建新的work線程處理所有Intent請求。
2.IntentService會創建新的work線程來處理onHandleIntent()方法實現的代碼,因此無需關心多線程問題。
3.請求完成的時候,IntentService會自動停止。
4.Service的onBind會提供默認的實現,該方法返回null
5.Service的onStartCommand提供默認的實現,會將Intent添加到隊列中
用Service處理耗時操作容易造成ANR,而IntentService不會。
留待以後查看源碼。
瘋狂Android講義第二版