How do I kill an Activity when the Back button is pressed?

前端 未结 5 513
傲寒
傲寒 2020-11-30 04:59

I got an Activity that when it starts, it loads an image from the internet. In an effort to save memory, when the Activity is left by the back button being pressed, I want t

5条回答
  •  忘掉有多难
    2020-11-30 05:18

    public boolean onKeyDown(int keycode, KeyEvent event) {
        if (keycode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(true);
        }
        return super.onKeyDown(keycode, event);
    }
    

    My app closed with above code.

提交回复
热议问题