【发布时间】:2023-03-22 18:53:01
【问题描述】:
AndroidManifest.xml
<application android:name=".MyApplication"
android:icon="@drawable/icon"
android:label="@string/app_name"
>
<service android:name=".MyService"
android:exported="true">
<intent-filter>
<action android:name="android.service.myapp.MyService.actionA"/>
<action android:name="android.service.myapp.MyService.actionB"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
</application>
如果我使用以下代码,我的服务就会启动:
Intent intent = new Intent(context, MyService.class);
intent.setAction("android.service.myapp.MyService.actionA");
context.startService(intent);
但是如果我使用以下代码启动它,我的服务不会启动:
Intent intent = new Intent("android.service.myapp.MyService.actionA");
context.startService(intent);
【问题讨论】:
标签: android android-intent android-service intentservice