2014-10-27 32 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()的次序(据我所知)。