2

Possible Duplicate:
Android: Clear the back stack

Is there any way to clear the back_Stack when I am calling a new Activity which not present in the back_Stack?(I am using Api vesion 8).. pls Help?

Community
  • 1
  • 1
ShineDown
  • 1,881
  • 3
  • 21
  • 29
  • Here is the Link that will do the trick for you. [Back Stack Activities](http://stackoverflow.com/questions/5794506/android-clear-the-back-stack) – Lalit Poptani Aug 19 '11 at 12:50
  • similar to [Android: Clear the back stack](http://stackoverflow.com/questions/5794506/android-clear-the-back-stack) and [How to clear the Android Stack of activities?](http://stackoverflow.com/questions/4190429/how-to-clear-the-android-stack-of-activities) – Richard Le Mesurier Aug 22 '12 at 15:01

1 Answers1

5

Without knowing your precise requirements, it is difficult to give you an exact answer, but you can use tasks to achieve what you need. If you have 3 activities named A, B & C. If you set C to have a different taskAffinity to A & B in the Manifest, then a separate back stack is used for C. If you then set clearTaskOnLaunch="true" for A in the manifest, then the back stack will clear when the user leaves that task. So, app launch loads activity A. The user clicks a button which launches B. If the user now clicks back, they return to A. If from B the user clicks a button to launch C, then the back stack of the task for A & B is cleared, and if the user then hits back they are taken back to A.

A full explanation of this can be found at Handling Affinities and Clearing the back stack.

Mark Allison
  • 21,839
  • 8
  • 47
  • 46