Android 从最近的任务中清除我的应用程序是否会停止接收广播?
为了在后台接收广播,我创建了一个服务类。但一旦我从最近的任务中清除它,它就会停止接收广播。清除最近的任务后是否无法接收广播或有办法?根据您在清单中注册的操作,您的应用程序将由系统或其他应用程序触发(导出的广播设置为true) 在应用程序清单中指定Android 从最近的任务中清除我的应用程序是否会停止接收广播?,android,service,background,broadcastreceiver,Android,Service,Background,Broadcastreceiver,为了在后台接收广播,我创建了一个服务类。但一旦我从最近的任务中清除它,它就会停止接收广播。清除最近的任务后是否无法接收广播或有办法?根据您在清单中注册的操作,您的应用程序将由系统或其他应用程序触发(导出的广播设置为true) 在应用程序清单中指定元素: <receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true"> <intent-filter&g
元素:
<receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.INPUT_METHOD_CHANGED" />
<action android:name="your.package.action.CUSTOM_ACTION" />
</intent-filter>
</receiver>
不要忘记从清单中注册您的服务:
<service
android:name=".MyBackgroundService"
android:enabled="true"
android:exported="true" />
<service
android:name=".MyBackgroundService"
android:enabled="true"
android:exported="true" />
override fun onCreate() {
super.onCreate()
// register foreground service
this.startForeground(notificationServiceId, yourNotificationInstance)
}