Reputation: 7417
I want on button press to clear the activity stack , but leave not all activities. I want to leave the launcher activity in the stack (So if the back button is pressed to go to HomeScreen).
Does:
Intent launch = new Intent(context, LnewActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
clear ALL activities, or does it leave the launcher activity in the stack? It is not clearly said in the docs.
Upvotes: 1
Views: 851
Reputation: 2871
actually Intent.FLAG_ACTIVITY_CLEAR_TOP
searches for a allready created instance of the Activity
in the stack and closes all Activities
down to this one. If there is no instance of it in the stack it will clear nothing.
maybe you are looking for other flags like:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Upvotes: 0
Reputation: 7417
Actually it does leave the launcher Activity in the stack!
Intent intent = new Intent(this, Search.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Upvotes: 1