You can start each activity like startActivityForResult()
and check result of activity.
So, if you want to close first activity, you should set specific result of each activity and call finish()
. In each activity, you check result
in onActivityResult()
, so if you see your specified result, you should close this activity (or set result if it not first activity too)
In first activity, I want to start second
Intent i = new Intent(Activity1.this, Activity2.class);
startActivityForResult(i, 0);
In second activity, I want to start third
Intent i = new Intent(Activity2.this, Activity3.class);
startActivityForResult(i, 0);
So, In third activity I want to start fourth and close each other
Intent i = new Intent(Activity3.this, Activity4.class);
startActivity(i);
setResult(RESULT_OK);
finish();
And in each activity (1, 2) I should check method onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK);
finish();
}
}