Search code examples
androidnotificationsandroid-pendingintent

How to close app from notification


My Android app runs 50% of the time in background, and has a notification that, when I press it, pops up the main activity BusMap via a PendingIntent. Now, I also want to close the app when I remove the notification by sliding it to prevent it to run in the background. I don't want to create broadcasts just for this. I tried adding .setDeleteIntent(quitpendingintent) to the same notification builder, but failed.

Is there a "natural" way to do this?


Solution

  • AFAIK there is no Intent flag/mechanism that ends an Activity like you want so I think the easiest and cleanest way to do that is to use a BroadcastReceiver and finish the activity from there.

    From what you posted I think you know the way to do this using BroadcastReceiver but just in case here is a way to do that.