Stop running the application in the background?

How to stop the application running in the background in Android? I want my application to start working every time it loads. How to do this programmatically.

+6
source share
5 answers

Override the onStop method of your activity:

 @Override public void onStop(){ super.onStop(); finish(); } 

But I think it is a bad idea to restart the application every time. It is better to override the onStart method and restart here.

Actually, your application does not start in the background. Android OS saves it in memory or saves the state of your activity on the device (and then you can load it using the savedInstanceState parameter in the savedInstanceState method).

+6
source

You can use onResume to reboot or see here .

EDIT:

In fact, you need to use these functions to restart the application when the user moves it. enter image description here

+7
source

After adding finish ();

This code will completely stop the application.

 System.runFinalizersOnExit(true); System.exit(0); android.os.Process.killProcess(android.os.Process.myPid()); 
+4
source

The entire Android ecosystem is based on the fact that the user does not need to worry about “terminating” or “from scratch” the application. If you need to start the application every time from scratch, perhaps because you have tasks in your "scratch" that should not be there, and probably should be somewhere in onResume .

Please give us more details if you would like a more detailed answer.

+2
source

you must use Intent.FLAG_ACTIVITY_CLEAR_TOP to complete all other actions that are running in the action pool and call the first action in which you can ask to exit the application

0
source

Source: https://habr.com/ru/post/906471/


All Articles