how to close android app completely

前端 未结 7 1775
一个人的身影
一个人的身影 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:19

    To Quit Application on Button click use this code :

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

    Try it..

    To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.

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

提交回复
热议问题