简体   繁体   English

在应用程序中单击后退按钮时,如何定义活动?

[英]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 . 使用startActivityForResultonActivityResult

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.

相关问题 如何设置Android后退按钮(Java)? - How do i set up the Android Back-Button (Java)? 如何检测用户何时单击了我的应用程序的 webview 中加载的网站的特定按钮? - How can I detect when a user clicked a particular button of a website loaded inside the webview of my app? 当我单击该按钮时,我的应用程序崩溃,这将带我进入Java,Android Studio上的另一个活动 - My app crashes when I clicked the button which will take me the another Activity on Java, Android Studio 单击电话后退按钮时重置活动 - Reset Activity when phones back button is clicked Android-单击启动图标或单击后退按钮时如何恢复上一个活动 - Android - How to resume the last activity when launched icon is clicked or when back button is clicked 如何使用Android后退按钮在我的应用中移回而不是关闭我的应用? - How can I use the Android back button to move back within my app instead of closing my app? 当我单击图像按钮时,如何将 ImageButton 放入会导致另一个活动的片段中 - How can I put ImageButton in Fragment that will lead to another activity when I clicked the Image Button 当我按返回按钮时,我的活动重新开始 - My Activity is restarts when i press back button 单击后退按钮两次时,关闭应用程序 - Close the app when back button clicked twice 单击设备中的后退按钮时退出应用程序 - Exit the app when back button in device is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM