I have this application flow:
Activity 1-> Activity 2-> Activity 3-> Home Activity
Now when the user switches from Activity3 to Home Activity I want to finish off all the previous activities. So the user cannot go to the previous activities.
I do not want use finish() as all the 3 activities form filling.
I tried
Intent.FLAG_ACTIVITY_CLEAR_TOP
But it does not seems to work
The right way is to use intent flags FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK.
Intent homeIntent=new Intent(this,HomeActivity.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(homeIntent);
CLEAR_TASK will clear all the previous activities in the task (if any) and make the new activity (HomeActivity) the root activity of the task. This flag should be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
Intent.FLAG_ACTIVITY_CLEAR_TOP should be used in case, if you are at ActivityHome (lanuched normally without any flag) and want to go back to activity_1 and also want to close activity_2 and activity_3 to be cleared from task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With