【发布时间】:2010-06-25 21:47:17
【问题描述】:
我正在关注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>
现在在 BroadcastReceiver MyStartupIntentReceiver 的 onReceive 方法中启动这个服务
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.wissen.startatboot.MyService");
context.startService(serviceIntent);
}
如您所见,它使用意图过滤器,并且在启动服务时添加操作。 我可以用吗
startService(new Intent(this, MyService.class));
一个比另一个有什么优势?
【问题讨论】:
标签: android service intentfilter