2014-10-27 31 views
4

關注this question,我有疑問。IntentService平行執行

讓我們在我的應用程序了說我定義開機後自動啓動2個意圖服務,即

<application> 
    <receiver android:name=".InterntService1" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 

      <category android:name="android.intent.category.HOME" /> 
     </intent-filter> 
    </receiver> 
    <receiver android:name=".InterntService2" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 

      <category android:name="android.intent.category.HOME" /> 
     </intent-filter> 
    </receiver> 
</application> 

現在,這是否意味着IntentSerivce1已經完成後IntentSerive2纔會執行?

or both service1 & 2可以並行執行嗎?

回答

2

您發佈的清單包含2 BroadcastReceiver s的條目,而不是2 Service s。在啓動時,Android會調用這些BroadcastReceiver中的每一個的onReceive()方法。由於onReceive()方法在主線程上運行,因此不能同時調用這兩種方法,因此將調用其中一個,然後調用另一個。沒有定義調用onReceive()的次序(據我所知)。