I have two different activities. The first launches the second one. In the second activity, I call System.exit(0) in order to force the application to close, bu
I use this:
1) The parent activity call the secondary activity with the method "startActivityForResult"
2) In the secondary activity when is closing:
int exitCode = 1; // Select the number you want
setResult(exitCode);
finish();
3) And in the parent activity override the method "onActivityResult":
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
int exitCode = 1;
if(resultCode == exitCode) {
super.setResult(exitCode); // use this if you have more than 2 activities
finish();
}
}
This works fine for me.