0

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.

enter image description here

enter image description here

this is the result when i press the Close button.

This is the result when i press the close button

CODE

finish();
AlanRubinoff
  • 385
  • 9
  • 30
  • finish() won't close the whole application. it close only the activity. Are you sure the bottom one is the same activity you called finish()? – Chatura Dilan Sep 16 '15 at 13:44
  • It is not your responsibility to close the application. Android does that for you. But you could put your app into background by sending the user to the homescreen. – JacksOnF1re Sep 17 '15 at 08:25

4 Answers4

2

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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
1

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);
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You could call Process.killProcess(Process.myPid()) and kill the entire app but its not the beat practice as mention in these posts post and this one here and as for calling the finish() it is as said by Tanis.7x

Community
  • 1
  • 1
Vaibhav Barad
  • 625
  • 8
  • 17
0

try to add

System.exit(0);

after finish();