I want to clear the activity stack when the user comes back to the dashboard screen. To achieve only one entry point for all the links I have on the dashboard.
How to clear all the activity stacks programmatically?
I know one option of firing the Intent of dashboard activity with the Intent.CLEAR_TASK
and Intent.NEW_TASK
flag.
CodePudding user response:
When you call startActivity on the last activity you could always use
Intent.FLAG_ACTIVITY_CLEAR_TOP
as a flag on that intent.
Read more about the flag here.
CodePudding user response:
you can try this to clear the activity stack.
Intent intent = new Intent(CurrentActivity.this, dashboardActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
CodePudding user response:
For this, I use the FLAG_ACTIVITY_CLEAR_TOP
flag for starting Intent
(without FLAG_ACTIVITY_NEW_TASK
)
and launchMode = "singleTask"
in manifest for launched activity.
Seems like it works as I need - the activity does not restart and all other activities are closed.