简体   繁体   中英

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.

在此处输入图片说明

在此处输入图片说明

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.

Say you have two Activities, ActivityOne and ActivityTwo . ActivityOne calls startActivity(new Intent(this, ActivityTwo.class)) to start ActivityTwo . If you now call finish() within ActivityTwo , the first activity will be displayed again.

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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