简体   繁体   English

从最近的应用程序中删除应用程序时,“前台”服务将被终止

[英]“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.

相关问题 从 Android 12 中的最近应用程序中删除应用程序时,音乐播放器前台服务停止 - Music Player Foreground service Stops when App is removed from recent apps in Android 12 即使应用程序被杀死,我怎样才能让我的应用程序运行? 从最近的应用程序中删除时在某种意义上被杀死 - How can i make my app run even when app is killed? killed in the sense when it is removed from recent apps android-从最新应用中删除的应用取消了前台通知 - android - foreground notification is cancelled on app removed from recent apps Android 6.0:正在删除应用程序时删除前台服务 - Android 6.0 : Foreground service is being removed when app is being killed 从最近的应用程序列表中删除后,我的应用程序被杀死 - My application is getting killed when removed from recent apps list 使用服务时从最近的任务中删除应用程序不会被杀死 - App isn't killed when removed from recent tasks when using service 当用户从最近的应用程序中关闭应用程序时,Sticky Service被杀死 - Sticky Service is getting killed when user closes app from recent apps 从最近的应用程序中删除应用程序后继续服务 - continuing service after app is removed from recent apps 我想在应用被最近的应用杀死时显示通知 - I want to show notification when app killed from recent apps 只希望将警报从“最新应用”中删除或用户被强制杀死时死亡 - Only want Alarm to die when removed from Recent Apps or user forced killed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM