简体   繁体   English

Android Studio应用程序未在finish()上关闭

[英]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, ActivityOneActivityTwo 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);

你可以称之为Process.killProcess(Process.myPid()),并杀死整个应用程序,但它不是拍实践中提及的这些职位 ,这一次在这里并作为调用完成()它是由Tanis.7x如说

try to add 尝试添加

System.exit(0);

after finish(); 在finish()之后;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM