How to exit when back button is pressed?

前端 未结 12 1268
名媛妹妹
名媛妹妹 2020-11-27 11:47

When a user presses the back button on an intent, the application should quit. How can I ensure the application quits when the back button is pressed?

12条回答
  •  迷失自我
    2020-11-27 12:11

    finish your current_activity using method finish() onBack method of your current_activity

    and then add below lines in onDestroy of the current_activity for Removing Force close

    @Override
    public void onDestroy()
    {
        android.os.Process.killProcess(android.os.Process.myPid());
        super.onDestroy();
    }
    

提交回复
热议问题