简体   繁体   English

Android并从活动C弹出到活动A或B.

[英]Android and popping from Activity C to Activity A or B

I have three activities in my activity stack, A (main) -> B -> C. 我的活动堆栈中有三个活动,A(主要) - > B - > C.

A starts B starts C. A开始B开始C.

My C is a dialog box with one button that will take me to A and one button that will take me to B. The Activity B must therefore have history, so if C calls finish() I will always end up in B. 我的C是一个对话框,其中有一个按钮,它将带我到A和一个按钮,将我带到B.因此,活动B必须有历史,所以如果C调用finish()我将总是在B中结束。

Given this, how do I (efficiently) set this up? 鉴于此,我如何(有效地)设置它? ie how do I (efficiently) go from C to A? 即我如何(有效地)从C到A?

I assume that you want to finish() B if the user selects the A button on C. Have B start C for a result ( startActivityForResult() ) and have C send back to B the result. 我假设你想完成()B,如果用户选择C上的A按钮。让B为结果启动C( startActivityForResult() )并让C向结束发回B。 If the result is "go to A", then B can just finish(). 如果结果是“转到A”,则B可以完成()。

One way is to set up the onActivityResult method in activity B. 一种方法是在活动B中设置onActivityResult方法。

Based on the button clicked, return from activity C with different return codes, which you can access in the onActivityResult method of activity B. Based on the return code, you can either stay on the activity B, or close the activity which will take you to activity A. 根据单击的按钮,从活动C返回不同的返回代码,您可以在活动B的onActivityResult方法中访问。根据返回代码,您可以保留活动B,或关闭将带您的活动活动A.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM