How to limit the number of the same Activity on the stack for an Android application
Posted
by johnrock
on Stack Overflow
See other posts from Stack Overflow
or by johnrock
Published on 2010-05-10T03:10:56Z
Indexed on
2010/05/10
3:18 UTC
Read the original article
Hit count: 278
android
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?
© Stack Overflow or respective owner