How to remove notification when user kills application

Asked

Viewed 233 times

5

I have a notification that appears when a service is running and disappears when it stops running.

If the user kills the application with the service running, the notification stays there forever.

Is there any way to know when the user killed the app so I can remove the notification? How can I catch this event?

  • Tried to use the onDestroy()?

  • onDestroy() is only in the activities, is not it? I can not use because they are destroyed at other times that the notification and the service must be alive.

  • 1

    From what I’ve researched, there is onDestroy for Services also, http://developer.android.com/reference/android/app/Service.html#onDestroy()

  • But I guess that way it won’t work for you.

  • Actually, I even implemented it here. But apparently it’s not being called when the user kills the app.

  • 1

    Poisé will not work because it identifies that the application was closed through the onDestroy() gives Activity. In this case, even if Activity closes the Service will still be running, so it does not run the onDestroy of the service.

Show 1 more comment

1 answer

2


The method onTaskRemoved() service runs when the application is removed from the recent.

I just removed the notification on it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.