[英]How can I define the activity when the back-button is clicked in my App?
I am nearly finished with my first Android App, but there is one thing that still bothers me: I have an activity with EditText fields and a "Start"-button that leads to a new Activity. 我的第一个Android应用程序快要完成了,但是还有一件事让我感到困扰:我有一个带有EditText字段的活动和一个“开始”按钮,该按钮导致了一个新的活动。 When the user presses the back-button (the one thats on the phone), I get back to my first Activity.
当用户按下后退按钮(电话上的那个)时,我回到了我的第一个活动。 Can I change this and define a whole new Activity?
我可以更改它并定义一个全新的活动吗? A modified version of my first Activity?
我的第一个活动的修改版本?
Here is what I want to achieve: 这是我要实现的目标:
First Activity - - > (start-button clicked) - - > Second Activity - - > (back-button clicked) - - > First Activity, modified. 第一个活动-->(单击开始按钮)-->第二个活动-->(单击后退按钮)-->第一个活动,已修改。
Thanks for any help! 谢谢你的帮助!
Use startActivityForResult
and onActivityResult
. 使用
startActivityForResult
和onActivityResult
。
An example of this is here . 一个例子在这里 。
You will put your layout manipulation code as it were in the onActivityResult
method in your first activity, and start the second activity using startActivityForResult
. 您将把布局操作代码放在第一个活动的
onActivityResult
方法中,然后使用startActivityForResult
启动第二个活动。
override onBackPressed() in your second activity and start your modified activity from there. 在第二个活动中覆盖onBackPressed()并从此处开始修改后的活动。 Something like:
就像是:
@Override
public void onBackPressed()
{
//start your activity here
//make sure you remove the super call
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.