How to limit the number of the same Activity on the stack for an Android application

后端 未结 2 1126
攒了一身酷
攒了一身酷 2021-01-06 16:34

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 o

相关标签:
2条回答
  • 2021-01-06 17:03

    One option is to use Intent.FLAG_ACTIVITY_REORDER_TO_FRONT every time you launch an Activity so that if an instance exists it is brought to the front of the stack and not created every time. This way you are ensured that only one Activity will remain on stack.

    0 讨论(0)
  • 2021-01-06 17:25

    You might want to set your activity as singleTop -- this basically means that you can have multiple instances, but the app will reuse an instance if you try to launch an instance on top of itself. See the Android documentation on Activities and Tasks.

    0 讨论(0)
提交回复
热议问题