Panos
Panos

Reputation: 7417

Android clear activity stack and leave launcher activity in

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

Answers (2)

A. Binzxxxxxx
A. Binzxxxxxx

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);

Android Intent

Upvotes: 0

Panos
Panos

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

Related Questions