How to limit the number of the same Activity on the stack for an Android application
- by johnrock
Is this possible in an Android app? I want to make it so that no matter how many times a user starts activityA, when they hit the back button they will never get more than one occurence of activityA.
What I am finding in my current code is that I have only two options:
1. I can call finish() in activityA which will prevent it from being accessible via the back button completely, or
2. I do not call finish(), and then if the user starts activityA (n) times during their usage, there will be (n) instances when hitting the back button.
Again, I want to have activityA accessible by hitting the back button, but there is no reason to keep multiple instances of the same activity on the stack. Is there a way to limit the number of instances of an activity in the queue to only 1?