Android Activity堆栈和返回函数问题
我有四个活动,A、B、C 和 D。应用程序从活动 A 开始,然后通过使用明确的意图转到 B,然后以相同的方式转到 C,然后 D。从D,如果我想直接回到B或A,怎么办?
I have four activities, A, B, C and D. app starts with activity A, then it goes to B by using explicit intend, then C and then D in same way. From D, if I want to come back to directly B or A, how it can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,在 C 中。如果您在发送启动 Activity D 的意图后调用 finish(),当用户在 Activity D 中按下后退按钮时,她/他将被发送到 Activity A 或 B,具体取决于您启动 Activity C 的位置。
另一种方法是设置标志以清除顶部,如下所示:
最简单的方法是根据您希望应用程序中的流程的方式调用 finish() 。
For example, in C. If you call finish() after you send the intent to start Activity D when the user presses the back button in Activity D she/he will be sent to Activity A or B depending where you started activity C.
Another way is to set flag to clear top like this:
The easiest way is to call finish() depending on how you want the flow in your app to be.
在活动A中
在活动 B 中
在活动 C 中
解释
在活动“A”中,您开始一项新活动到“B”
2)在“B”活动中,使用 startActivityForResult 方法将一项活动启动到“C”
3)在“C”活动中,当您完成时,它显然会转到“B”活动,并带有您设置的结果代码。如果匹配,它将关闭“B”活动,并转到“A”活动
4)这是跳过一项或多项活动的一个简单技巧
in Activity A
in Activity B
in Activity C
Explanation
1)in activity "A" ur starting one fresh activity to "B"
2)in "B" activity ,ur starting one activity to "C" ,using startActivityForResult method
3)in "C" activity ,when u finish,it obviously go to "B" activity,with result code which u set.and if it's match it will close "B" activity ,and go to "A" activity
4)This is one simple trick to skip one or more activity