启动活动与后退按钮 [英] Starting Activity with back button
问题描述
我在开发Android的应用程序,在那里我正在寻找一个解决方案。
I'm developing an application in android, where i'm looking for a solution.
有一个活动(例如A1),从其中通过点击一个按钮,用户进入到另一个活动(说A2)。现在,一旦用户与A2的活动结束后,他点击后退按钮,返回到previous活动A1。 以及这是一个非常公知的事实,即,A1将在此时自动恢复。
There is an Activity(say A1) from which by clicking a button, user goes to another Activity(say A2). Now once the user has finished with A2 activity, he clicks back-button, to go back to previous activity A1. Well this is a very known fact that, A1 will resume automatically at this point.
但我想它以不同的方式(因为我的应用程序要求)。
But I want it in a different way (because my application demands that).
在,如果我去从A1活动A2,A1被破坏;和,而在A 2为如果被点击后退按钮,A1被重新创建。
Once if i go to activity A2 from A1, A1 is destroyed; and while being in A2 if back-button is clicked, A1 is created again.
谁能告诉我如何使这项工作?
Can anyone tell me how to make this work?
推荐答案
您可以使用:
public void onBackPressed()
{
//do whatever you want the 'Back' button to do
//as an example the 'Back' button is set to start a new Activity named 'NewActivity'
this.startActivity(new Intent(YourActivity.this,NewActivity.class));
return;
}
在这里看看:<一href="http://www.41post.com/1685/programming/android-changing-the-back-button-behaviour">http://www.41post.com/1685/programming/android-changing-the-back-button-behaviour
这篇关于启动活动与后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!