安卓:模拟后退按钮两次 [英] Android: Simulate the back button twice

查看:134
本文介绍了安卓:模拟后退按钮两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情况我有一个三步注册过程。每一步都包含在其自己的活动 - 给他们打电话A,B和C.只有当我到达第三步结束时,我能够可靠地验证了一个输入端(和电子邮件地址,我发使用PHPMailer的确认) 。如果返回一个错误,我要回到A一路,这是在输入电子邮件地址。

I have a situation where I have a three step registration process. Each step is contained in its own activity - call them A, B, and C. Only when I get to the end of step three, can I reliably validate one of the inputs (and email address to which I send a confirmation using PHPMailer). If this comes back with an error, I want to go all the way back to A, which is where the email address is entered.

这是只调用的意图很容易。然而,我要保留,使得它们不必再次输入该用户最初输入的输入值。从理论上说,要做到这一点最简单的方法是调用完成()的两倍。但是,这并不因为调用一次控制权转移回B和第二个呼叫从未发生过工作。

This is easy enough by just calling an Intent. However, I want to retain the input values that the user entered originally so that they don't have to enter them again. Theoretically, the easiest way to do this is to call finish() twice. But this doesn't work since calling it once transfers control back to B and the second call never happens.

有一个简单的方法来做到这一点,或者我要叫意图,然后以某种方式填充通过其他方法的领域?谢谢!

Is there a simple way to do this, or do I have to call Intent and then somehow populate the fields through another method? Thanks!

推荐答案

我不知道我完全得到你,但你可以使用标记 FLAG_ACTIVITY_CLEAR_TOP 来把它带回来A和去除B点。

I'm not sure I completely get you but you could use the flag FLAG_ACTIVITY_CLEAR_TOP to bring it back to A and remove B.

Intent i = new Intent(C.this, A.class)
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();

当你的错误运行此code和它会带来一个备份。而如果后退按钮pressed你仍然会到B

Run this code when you get the error and it will bring A back up. And if the "Back" button is pressed you will still get to B.

你有另一种选择是在存储的东西像信息的共享preferences 并加载从那里数据,但是这可能是不必要您的具体情况。

Another option you have is to store the information in something like SharedPreferences and load the data from there but this may be unnecessary for your situation.

这篇关于安卓:模拟后退按钮两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆