我下面的教程来setup a service to start on boot其中代码的最后一段是:启动服务时是否需要添加意图过滤器?
请在AndroidManifest.xml该服务的条目
<service android:name="MyService">
<intent-filter>
<action
android:name="com.wissen.startatboot.MyService" />
</intent-filter>
</service>
现在开始在广播接收器MyStartupIntentReceiver的方法的onReceive此服务as
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.wissen.startatboot.MyService");
context.startService(serviceIntent);
}
正如您所看到的,它使用intent-filters,并在启动服务时添加操作。 我可以只用
startService(new Intent(this, MyService.class));
相比其他什么一个优势?