0

I have an android app, which I would like to close if it is open in background by sending a notification. Is this possible. If yes, how?

AL.
  • 36,815
  • 10
  • 142
  • 281
milan m
  • 2,164
  • 3
  • 26
  • 40
  • 1
    Technically, this is possible. However, I think some Android guidelines say you shouldn't explicitly close your app from within the code. See discussion on the topic [here](http://stackoverflow.com/q/2033914/3372061). – Dev-iL Oct 06 '16 at 12:24

3 Answers3

1

Implementation of the complete FCM code to handle notifications can be found here. Doesn't make sense to copy everything here, given is simply following the official guide.

Then, inside your handler simply do a System.exit(0);

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
0

yes, check the notification string and if it's true the app close

if(stringFromFirebase.equals("close_app")) {
        System.exit(0);
}
Daniel Juric
  • 128
  • 1
  • 10
0

try this, it will kill entire app process.

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
Keyur Thumar
  • 608
  • 7
  • 19