Is it possible to listen for when a user cancels a Notification in Android?
Pergunta
I'm interested to know when a user cancels a Notification from by application - is this possible? I'd like to listen for the event and then stop a service that runs in the background.
Solução
There is not any way to see if notification was deleted by user. You can make notification "persistent" - it can't be cleared - and start some action when user clicks on it.
Outras dicas
You know that we append a PendingIntent in notification, so by using that intent we can launch an activity which may close the service and then call finish() on itself to go away. The entire process might be fast enough that a user may not notice any hiccup
You can set a PendingIntent sent when the notification is cleared explicitly by the user. Please, take a look over here: Notification.Builder setDeleteIntent (PendingIntent intent)