[英]Android studio application doesn't close on finish()
So i have a button in the bottom layout , when i press it i intend to close the application. 所以我在底部布局中有一个按钮,当我按下它时,我打算关闭该应用程序。
instead what seems to happen is, what i think is the viewflipper closes and the bottom and top bar remain active and the application doesn't close. 相反,似乎发生的是,我认为是viewflipper关闭,底部和顶部栏保持活动状态,应用程序未关闭。
this is the result when i press the Close button. 这是当我按下“关闭”按钮时的结果。
CODE 码
finish();
As per the documentation, finish()
closes the Activity that you call finish()
on, not your entire application. 根据文档,
finish()
关闭您调用finish()
活动,而不是整个应用程序。
Say you have two Activities, ActivityOne
and ActivityTwo
. 假设您有两个Activity,
ActivityOne
和ActivityTwo
。 ActivityOne
calls startActivity(new Intent(this, ActivityTwo.class))
to start ActivityTwo
. ActivityOne
调用startActivity(new Intent(this, ActivityTwo.class))
启动ActivityTwo
。 If you now call finish()
within ActivityTwo
, the first activity will be displayed again. 如果现在在
ActivityTwo
调用finish()
,则将再次显示第一个活动。
This is tied to the back stack - when you finish one Activity, the next Activity on the back stack will be displayed. 这与后堆栈相关联 -当您完成一个活动时,将显示后堆栈上的下一个活动。
If you want to close all of your Activities, you must call finish()
on each of those Activities. 如果要关闭所有活动,则必须在每个活动上调用
finish()
。
You can use 您可以使用
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startMain.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startMain.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
try to add 尝试添加
System.exit(0);
after finish(); 在finish()之后;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.