Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit completely from android app

I want to exit entire app by clicking exit button. Actually I am using exit button instead of log-out. So whenever user clicks on it, it should finish complete app but it destroys only last running activity. What should i do now? I am using this method in my code, any help will be appreciated, thanks in advance.

         public void exit(View v){
                finish();
                System.exit(0);
            }

I have also used following code but it kills only last running activity and not the complete application.

             public void exit(View v){
                android.os.Process.killProcess(android.os.Process.myPid());
                System.exit(1);
            }
like image 476
SparrOw Avatar asked Jan 10 '23 07:01

SparrOw


2 Answers

There is an alternative for otherwise killing your app completely. Minimize it and the Android system will kill it automatically when necessary. To do so,

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Furthermore, this SO question may help: How to close android app completely

like image 94
Abhishek Verma Avatar answered Jan 12 '23 21:01

Abhishek Verma


If you really, really have to, do this:

public void exit(View v){
    finish();
    android.os.Process.killProcess(android.os.Process.myPid());
}
like image 23
HHK Avatar answered Jan 12 '23 19:01

HHK