退出/完成一个应用程序/活动 - 机器人 [英] Exit/Finish an app/activity - android
问题描述
我有4活动说 ACT1
, ACT2
, ACT3
和 ACT4
。
在ACT1的按钮以打开ACT2,在ACT2 ACT3打开一个按钮,在ACT3的按钮以打开ACT4。
I've got 4 activities say Act1
, Act2
, Act3
and Act4
.
A button in Act1 opens Act2, a button in Act2 opens Act3, a button in Act3 opens Act4.
我想两件事情要做:
-
我在ACT4一个按钮,将用户指引到ACT1的概率是,当用户点击回ACT1,我想关闭打开ACT4的应用程序,而不是..
I've a button in Act4 which directs the user to Act1, the prob is when the user clicks back in Act1, i want to close the app instead of opening the Act4..
我已经在选项菜单中的退出的所有活动,当用户选择了它,我想关闭的要回previous活动的应用程序来代替。
I've option in menu 'exit' in all activities when the user choose it, i want to close the app instead of going back to previous activity.
使用完成()尝试;
,但它不符合我的要求。
Tried using finish();
but it didn't meet my requirements.
推荐答案
使用低于code在 ACT4
'个 menu.xml文件
的退出按钮 -
Use below code in your Act4
'th Menu.xml
's exit button -
Intent intent = new Intent(Act4.this, Act1.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
和,在你的第一个活动的的OnCreate()
mehthod只要把下面code -
And, in your first activity's oncreate()
mehthod just put below code -
if (getIntent().getBooleanExtra("EXIT", false))
{
finish();
}
这会退出你的应用程序。
This will be exit your app.
这篇关于退出/完成一个应用程序/活动 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!