销毁前景通知时,该服务被打死 [英] Destroy foreground notification when the service get killed
本文介绍了销毁前景通知时,该服务被打死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个前台服务下载一些内容,形成网络。
I have a foreground service to download some contents form the web.
不幸的是,由于该报告<错误href="http://stackoverflow.com/questions/20636330/start-sticky-does-not-work-on-android-kitkat-edit-and-jelly-bean/20681898#20681898">here我的服务被杀害时,接收器接收在我服务的广播,但它通知将不会被杀死,我看到下面的日志中我logcat的:
Unfortunately, due to bug which reported here my service being killed when a receiver received a broadcast within my service but it's notification won't be killed and I saw the following log in my logcat:
I/ActivityManager(449): Killing 11073:my-package-name/u0a102 (adj 0): remove task
反正是有破坏前景通知时,它的父服务获得由OS被杀?
Is there anyway to to destroy foreground notification when it's parent service get killed by OS?
推荐答案
使用的 stopForeground:
@Override
public void onDestroy() {
// as the bug seems to exists for android 4.4
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.KITKAT)
{
stopForeground(true);
}
super.onDestroy();
}
或
public void onTaskRemoved (Intent rootIntent)
{
// as the bug seems to exists for android 4.4
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.KITKAT)
{
stopForeground(true);
}
}
这篇关于销毁前景通知时,该服务被打死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文