Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy foreground notification when the service get killed

Tags:

java

android

I have a foreground service to download some contents form the web.

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

Is there anyway to to destroy foreground notification when it's parent service get killed by OS?

like image 372
NullPointer Avatar asked Oct 20 '22 10:10

NullPointer


1 Answers

Service ending remove the foreground notification.

@Override
public void onDestroy() {
    // mycleanup first
    stopForeground(true);
    super.onDestroy();
}
like image 76
danny117 Avatar answered Oct 23 '22 02:10

danny117