Reputation: 11999
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
Upvotes: 3
Views: 4302
Reputation: 8034
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.
Upvotes: 8
Reputation: 5260
Hi i am not sure what you are doing, once i face the same type of problem so sharing with you
if you are using addFlags
than instead of this use setFlags
Have a try with intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
instead of intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent(getApplicationContext(),
DesiredActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Upvotes: -1