0

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?

Luis A. Florit
  • 2,169
  • 1
  • 33
  • 58
  • What does "close the app" mean? What does "but failed" mean? – CommonsWare Dec 22 '17 at 20:11
  • @CommonsWare: "close the app" = System.exit(0); "but failed" = not System.exit(0);. I know this is not the supposed way for an Android app to "close", but I prefer it this way. – Luis A. Florit Dec 22 '17 at 21:56

1 Answers1

0

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.

fmaccaroni
  • 3,846
  • 1
  • 20
  • 35
  • 1
    I didn't want to implement a `BrodcastReceiver` just to finish the activity.... but ok. I implemented the `BrodcastReceiver` through a `.setDeleteIntent(intent)` in the `Notification.builder`. Thanks! – Luis A. Florit Dec 22 '17 at 22:45