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

后端 未结 2 1133
攒了一身酷
攒了一身酷 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.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题