What happens when System.exit (0) executes?
The VM stops further execution, and the program terminates.
Now in your case, the first action is returned due to the activity stack. So when you move from one operation to another using Intent , execute finish() current activity like this.
Intent intent=new Intent(getApplicationContext(), NextActivity.class); startActivity(intent); CurrentActivity.this.finish();
This ensures that there is no activity when the application is closed.
And to exit the application, use this code:
MainActivity.this.finish(); android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); getParent().finish();
And you should not use System.exit() if your application uses any resource in the background, for example a music player playing a song from the background or any application that uses Internet data in the background or any widget that depends on your application.
For more information, follow the links:
source share