In Android I have some activities, let\'s say A, B, C.
In A, I use this code to open B:
Intent intent = new Intent(this, B.class);
startActivity(inte
The given code works correctly. I have tried in the Application Life Cycle sample.
I haven't got B and C in the back stack after starting activity A with flag, FLAG_ACTIVITY_CLEAR_TOP
i called activity_name.this.finish()
after starting new intent and it worked for me.
I tried "FLAG_ACTIVITY_CLEAR_TOP" and "FLAG_ACTIVITY_NEW_TASK"
But it won't work for me... I am not suggesting this solution for use but if setting flag won't work for you than you can try this..But still i recommend don't use it
logout.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); logout.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
I found the answers here a little misleading because the code in the original question seems to work fine for me?
With A being the root activity, starting it from B or C only with FLAG_ACTIVITY_CLEAR_TOP does remove B and C from the back stack.
This bothers me for a long time .Finally I worked it out by doing this:
In fragment,use:
Intent intent = new Intent(view.getContext(), A.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
In Activity,use(add one more intent flag Intent.FLAG_ACTIVITY_CLEAR_TASK
compared to fragment):
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
As per Wakka in Removing an activity from the history stack...
Add android:noHistory="true"
attribute to your <activity>
in the AndroidManifest.xml
like this:
<activity android:name=".MyActivity"
android:noHistory="true">
</activity>