0

Is it possible when the user clicks on the back button to shut down the whole application, not just the activity but the whole application?

enter image description here

I am currently using the following code:

@Override
public void onBackPressed() {
     finish();
     System.exit(0);
    }

The problem with this code is that it shuts down the current activity rather than the application, and it often gets an error.

Probably I was opening activities one over the other without paying attention, maybe that's the problem, I'm pretty new to android

Niklaus
  • 159
  • 1
  • 2
  • 11

1 Answers1

1

You can try like below

android.os.Process.killProcess(android.os.Process.myPid());
Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29