Exit Android Application

How to close the Android application if more than one action is active?

+9
android android-emulator
Feb 28 '11 at 8:33
source share
8 answers

I got an easy solution to this problem

As a result of the action, click the "Exit" button, go to the first action using the following source code. Read also the documentation FLAG_ACTIVITY_CLEAR_TOP.

Intent intent = new Intent(ExitConfirmationActivity.this, FirstActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); 

Now override onResume () of the first action using finish ()

+9
Mar 01 2018-11-11T00:
source share

Blog post Exiting the Android app will show you how to quit the Android app:

When the user wants to exit all open actions, they must click the button that loads the first action that starts when the application starts, in my case "LoginActivity".

  Intent intent = new Intent(getApplicationContext(), LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("EXIT", true); startActivity(intent); 

The above code clears all actions except LoginActivity. LoginActivity is the first action that occurs when a user launches a program. Then put this code inside LoginActivity onCreate to signal when it should destroy itself when an Exit message is sent.

  if (getIntent().getBooleanExtra("EXIT", false)) { finish(); } 
+14
Feb 28 2018-11-11T00:
source share

The answer is simple: you really do not need to “close” the Android application. If no activity is shown anymore, the system will kill the process after a while. Users can close actions by clicking the back button. Reto Meyer explains this pretty well here: http://blog.radioactiveyak.com/2010/05/when-to-include-exit-button-in-android.html

+2
Feb 28 '11 at 8:48
source share

You can also read this topic; this is very useful, to say the least: Exit the Android app - frowned at it?

+2
Feb 28 '11 at 9:22
source share

Well, you should not close your applications, as the system deals with this. Refer to posts / topics in other answers for more information.

However, if you really want this, you can still call System.exit (0); as in any other Java application.

EDIT

 ActivityManager actmgr = (ActivityManager) this.getSystemService (Context.ACTIVITY_SERVICE); actmgr.restartPackage ("com.android.your.package.name"); 

I remembered something. I tried to use this code to restart my application, but I only managed to kill my application. You can try and see if this works for you.

+2
Feb 28 2018-11-11T00:
source share

I asked a couple of weeks ago a question . Go through the answers and comments for more promising and possible solutions.

Disabling IMO from the application depends on what your application is doing and on user expectations. Although I understand the rationale for the absence of the exit button, I also believe that this is a choice that the application developer must make depending on the situation.

+1
Feb 28 '11 at 11:39
source share

As soon as your last activity stops focusing, Android will unload your process in accordance with the current needs of the system / free resources. You do not have to worry about this - just use the onStart, OnStop, etc. lifecycle to manage your state.

0
Feb 28 '11 at 9:23
source share

If you want to exit one Android activity, this will return you to a previous action or another action from a specific place in the current activity.

 finish(); System.exit(0); 
0
Jul 17 '12 at 11:28
source share



All Articles