简体   繁体   English

Android 6.0:正在删除应用程序时删除前台服务

[英]Android 6.0 : Foreground service is being removed when app is being killed

I created Notification in onStartCommand of my Service class to run a foreground service. 我在Service类的onStartCommand中创建了Notification来运行前台服务。

In previous versions of Android (version < 6.0) the service keeps running and the Notification can not be removed even if I kill the app from the recent apps menu. 在以前版本的Android(版本<6.0)中,即使我从最近的应用程序菜单中删除了应用程序,该服务也会继续运行并且无法删除Notification I'm also using BOOT_COMPLETED intent filter for my BroadCastReceiver so that my service starts as my device restarts. 我还使用BOOT_COMPLETED意图过滤器对我的BroadCastReceiver ,这样我的服务启动我的设备重新启动。 Everything is working fine in Lollipop and previous versions. Lollipop和之前版本的一切都运行良好。 But when I tested in my Marshmallow device, when I clear my ram from recent app, the foreground service is also killed and the Irremovable Notification also being removed. 但是当我在我的Marshmallow设备中测试时,当我从最近的应用程序中清除我的ram时,前台服务也被杀死,并且不可删除的通知也被删除。 As a result my app stops working. 结果我的应用程序停止工作。 Service does not start when the device restarts either. 设备重启时,服务无法启动。

Is it causing by the famous DOZE MODE implemented in Android 6.0 and Higher ? 它是由Android 6.0及更高版本中实现的着名DOZE MODE引起的吗? Or there is something else ? 或者还有其他什么? Please help me someone ? 请帮帮我一个人? I asked for help earlier but couldn't resolve the problem. 我之前请求过帮助,但无法解决问题。

you have to add process attribute in manifest 你必须在清单中添加进程属性

<service
 android:name=".YourServiceName"
 android:process=".process"
 android:enabled="true"
 android:exported="true"></service> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM