I’m trying to figure out how to run a piece of code when a notification gets cleared.
I’ve found that the Notification class provides a deleteIntent which is run when the notification is cleared, but I have been unable to find any resource that explains how I could go about getting this to run a piece of code within my application.
I was wondering if anyone had any suggestions of how I could achieve this, or could point me towards a good tutorial that will explain how I could go about achieving this.
A
PendingIntentcan either do:startActivity()on anIntentthat you supply, orstartService()on anIntentthat you supply, orsendBroadcast()on anIntentthat you supplySince you probably already have a service (otherwise, I’m not sure why you have a
Notificationin the first place), I’d use the second option. Use thegetService()static method onPendingIntent, handing it anIntentidentifying your service. When the user gets rid of theNotification, your service will be called withonStartCommand().