如何操作Activity返回栈?
我想实现以下逻辑。我有 4 个活动 A、B、C 和 D。
流程是 A -> B-> C-> D
当用户从 A -> 导航时C 他应该能够通过按后退按钮返回到之前的活动。但是在到达 D 后,按后退按钮应该将他带到活动 A。再次按后退按钮应该退出应用程序,而不是把他带回到 B/C/D。我该怎么做。
I want to implement the following logic. I have 4 activites A, B, C and D.
The flow is A -> B -> C -> D
When the user navigates from A -> C he should be able to get back to the previous activities by pressing the back button. But after reaching D pressing the back button should take him to activity A. And pressing the back button againg should exit the application instead of taking him back to B / C / D. How do I do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您是否真的可以像您在标题中建议的那样操作应用程序堆栈。
我的应用程序在 opengl 中运行,所以我实际上从未将一个 Activity 更改为另一个 Activity,但我认为以下原则也适用:
为什么不自己调用您想要的 Activity ?
在后退按钮事件中处理这个问题真的很简单。
背面按下-> 如果您在活动 A 中,则加载您想要的活动
,然后退出
I don't know if you actually can manipulate the stack of application like your suggesting in your title.
My app runs in opengl so I never actually change form one Activity to another but I think the following principle will also work:
Why don't you call the Activity you want yourself ?
it is really straight forwards in the back button event to handle this.
on back pressed -> load activity you want
if your in activity A then exit