I want the application process to be killed when the user slides the notification off the screen or hits the clear all notifications button.
Is there a way to implement this?
I want the application process to be killed when the user slides the notification off the screen or hits the clear all notifications button.
Is there a way to implement this?
DeleteIntent: DeleteIntent is a PendingIntent object that can be associated with a notification and gets fired when the notification gets deleted.
You can set the Pending Intent to a broadcast Receiver and then perform any action you want.
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);
Builder builder = new Notification.Builder(this):
..... code for your notification
builder.setDeleteIntent(pendingIntent);
MyBroadcastReceiver
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//code to kill app
c̶o̶n̶t̶e̶x̶t̶.̶f̶i̶n̶i̶s̶h̶A̶f̶f̶i̶n̶i̶t̶y̶(̶)̶;̶
ActivityCompat.finishAffinity((Activity)context);
}
}
reference: catch on swipe notification event