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);
}
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
If you really, really have to, do this:
public void exit(View v){
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With