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(intent);
In B I use this code to open C:
Intent intent = new Intent(this, C.class);
startActivity(intent);
When the user taps a button in C I want to go back to A and clear the back stack (close both B and C). So when the user use the back button B and C will not show up, I've been trying the following:
Intent intent = new Intent(this, A.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
But B and C are still showing up if I use the back button when I'm back in activity A. How can I avoid this?
use this code for starting new activity and close or destroy all other acivity stack or back satack...
Intent.FLAG_ACTIVITY_CLEAR_TOP
will not work in this case. Please use(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
For more detail please check out this documentation.
android:launchMode="singleTop"
to the activity element in your manifest for Activity Aintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
andintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
when starting Activity AThis means that when Activity A is launched, all tasks on top of it are cleared so that A is top. A new back stack is created with A at the root, and using
singleTop
ensures you only ever launch A once (since A is now on top due to..._CLEAR_TOP
).Add NO History Flag in the intent.
In activity B, start the activity C as below >>>>>>
Either add this to your
Activity B
andActivity C
or
Override
onBackPressed
function to avoid back pressing with areturn
.If your application has minimum sdk version 16 then you can use finishAffinity()
Finish this activity as well as all activities immediately below it in the current task that have the same affinity.
This is work for me In Top Payment screen remove all back-stack activits,
http://developer.android.com/reference/android/app/Activity.html#finishAffinity%28%29