[英]“foreground” service is killed when App is removed from recent apps
I have an App with a foreground service (which calls startForeground
) which shows a notification. 我有一个带有前台服务的应用程序(调用startForeground
),该服务显示通知。 The notification is set to ongoing and updated by the service every second. 该通知设置为正在进行中,并由服务每秒更新一次。
The service works perfectly fine in most devices, expect some of the devices from MI or Oppo. 该服务在大多数设备上都可以正常运行,需要MI或Oppo的某些设备。 In those devices the service gets killed and notification is removed as soon as the app is removed from the recent tasks list. 在这些设备中,一旦将应用程序从最近的任务列表中删除,该服务就会被终止,通知也将被删除。
From the Android documentation, a foreground service is not supposed to be killed just like that. 根据Android文档,前台服务不应该那样被杀死。
The AndroidManifest file lists the service as followed. AndroidManifest文件将服务列出如下。
<service
android:name=".IndicatorService"
android:enabled="true"
android:exported="false"
android:stopWithTask="false"
android:process=":background" />
As I said, I'm calling startForeground
with a notification in onStartCommand
in the Service. 就像我说的,我在服务的onStartCommand
中通过通知调用startForeground
。 The onStartCommand
returns START_REDELIVER_INTENT
. onStartCommand
返回START_REDELIVER_INTENT
。 I'm testing for Android 6+. 我正在测试Android 6+。
I know there are a number of questions around similar problem, but I could not find some satisfactory explanation and solution. 我知道围绕类似问题有很多问题,但是我找不到令人满意的解释和解决方案。
Specific questions. 具体问题。
1) Why is this happening in some devices? 1)为什么在某些设备中会发生这种情况?
2) What should be done to avoid a foreground service from being killed? 2)应该采取什么措施避免前台服务被杀死? What are some good/correct way to handle this? 有什么好的/正确的方法来解决这个问题?
I personally think the underlying logic of removing a recent task has been changed on those MI or Oppo devices. 我个人认为,删除这些近期任务的基本逻辑在那些MI或Oppo设备上已更改。
The documentation works for AOSP (and those passed CTS), but device vendors can customize Android in whatever way they want. 该文档适用于AOSP(以及通过CTS的那些文档),但是设备供应商可以按照他们想要的任何方式自定义Android。 They probably don't care about Android Compatibility . 他们可能不在乎Android兼容性 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.