Closing an application is not easy at all

I am trying to close the application using a button using this method: System.exit (0); But I am returning to another activity! How can i fix this? Thanks

0
source share
2 answers

Not recommended, but this should completely destroy the application.

android.os.Process.killProcess(android.os.Process.myPid());

To exit normally, you just need to call Finish() from your main action.

+1
source

You cannot use System.exit(0) . Use finish() instead. finish will finish out the action from the activity stack and destroy it. The previous action in the back stack is focused.

Check out this link and comments by Dianne Hackborn

https://groups.google.com/forum/#!topic/android-developers/Zhd1fRfHAAQ

Check out this link and comments by Romain Guy

https://groups.google.com/forum/#!topic/android-developers/G_D3pKnGLt0

Quote from commentary on Boston Streets

https://groups.google.com/forum/#!topic/android-developers/Y96KnN_6RqM

You should not call System.exit (). This can ruin Android’s workflow and lead to an uncomfortable user experience (for example, when you kill a process, the previous activity from which you highlight your activity may also disappear. Android may try to restart the process again and recreate that the parent accidentally killed -activity. but still).

 public static void exit (int code) Added in API level 1 Causes the VM to stop running and the program to exit. If runFinalizersOnExit(boolean) has been previously invoked with a true argument, then all objects will be properly garbage-collected and finalized first. Parameters code the return code. 

Rejected the application that was abandoned?

If you are looking for a navigation bar, use the action bar and navigation bar.

+2
source

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


All Articles