I been working on Android Native App , What i was trying to do is :
Activities - A -> B -> C Then A-> B -> C -> C .
From C Activity if it again point to C then i want to remove C , B from stack manually . On my back it should move only to A .
I tried finish() but problem is :
Activities - A -> B -> C Then A-> B -> C -> C on finish A -> B -> C required state A-> C .
Is anyone know how to catch all activities in stack and remove specific activities from stack ??
You can use this : In A activity while passing to B activity, the intent should be added with a flag FLAG_ACTIVITY_NO_HISTORY like this,
While moving to CActivity:
On backpress will take you to AActivity now.
In Activity C, when back button is pushed start activity A like this:
Then in Activity A's onCreate() do this
Step 1: Start activty for result A -> B -> C1 -> C2.. Call your Activity with startActivityForResult
Step 2: In C2 specify that you want to go back to A.. Whenever you are done with your activity write the below code
Step 3: Whenever C2 finishes , previsus stack activit's onActivityResult is called.. so u can check in C1 and B onActivityResult whether you have set any result bck.. and finish accordingly and impliment the following code in Activity B and c
While calling intent pass a flag called actvity clear top like this:
this complete example may help you...
In Activity C, override
onBackPressed
and add in something like:FLAG_ACTIVITY_CLEAR_TOP
will cause it to go down the stack to the existing copy of A Activity instead of starting a new one. From the docs: