活动堆栈管理

发布于 2025-01-08 02:41:38 字数 527 浏览 1 评论 0原文

我的活动管理遇到问题。因此,我的活动 A 会转到 B,如果您按 B 中的后退按钮,我希望它转到 A< /strong>,但也有一种情况,B将完成并转到C,如果我按C上的后退按钮,我想要它离开应用程序,基本上返回堆栈是空的。这样做的正确方法是什么?

我能想到的唯一方法就是这样。当 A 启动 B 时,它会在 A 上调用 finish(),而不是在 B 上调用 finish() 我覆盖后退按钮以开始 < strong>A,否则,如果满足某些条件,则在 B 上调用 finish() 并启动 C。必须覆盖后退按钮似乎我做错了什么。

感谢您的帮助。

I am having trouble with my activity management. So I have activity A which goes to B and if you press the back button in B I want it to go to A, but there is also a case where B will finish and go to C and if I press the back button on C I want it to leave the app, basically the back stack is empty. What is the correct way to do this?

The only way I can see to do this is like this. When A starts B it calls finish() on A than on B I override the back button to start A, other wise if certain conditions are met call finish() on B and start C. Having to override the back button seems like I am doing something wrong.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深已缘浅 2025-01-15 02:41:38

我最终通过 FLAG_ACTIVITY_CLEAR_TOP 的用户解决了这个问题,这是 nibha 在这篇文章中向我推荐的。 另一篇文章并致电在适当的地方完成()。

I ended up solving this problem through the user of the FLAG_ACTIVITY_CLEAR_TOP which was recommended to me by nibha on this post. Another Post and calling finish() in the appropriate places.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文