how to close android app completely

前端 未结 7 1761
一个人的身影
一个人的身影 2020-12-03 01:59

I created an android application with a logout option in onCreateOptionsMenu. The Logout works perfectly but when I press the back button again it takes me to t

7条回答
  •  再見小時候
    2020-12-03 02:09

    To Finish an Activity I'm using this code:

    public void appExit () {
        this.finish();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }  //close method
    

    or kill Process with this code:

    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);
    

提交回复
热议问题