How to kill my Android app?

I am working on an Android application that has a logout button. When I click on this, I need to completely close the application (I also do not want to run the application in the background). Could you advise me how I can achieve this. I tried with System.exit(0) and finish() .

+1
source share
3 answers

on the logout button try this code:

  finish(); moveTaskToBack(true); System.exit(0); 

I think this does not completely close your application, but will quit all actions.

+3
source

Android has a mechanism that allows you to safely close the application.

In the last action on the stack (usually the main or only the first that you run), override the onDestroy() method.

You can either call System.runFinalizersOnExit(true) , which ensures that all objects will be finalized and garbage will be collected when the application exits, or quickly delete the application through android.os.Process.killProcess(android.os.Process.myPid()) , if you want.

0
source

The finish () method starts the destruction of activity. therefore he must be here.

0
source

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


All Articles