I need to minimize the android application on back button click

后端 未结 3 656
花落未央
花落未央 2021-02-05 05:10

I need to minimize the application when back button is pressed.

I use following code to catch hardware back button click event


help me with the code of min

3条回答
  •  一向
    一向 (楼主)
    2021-02-05 06:16

    try this code, this will minimize Activity.

    public boolean onKeyDown(int keyCode, KeyEvent event)  
    {
         if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
         {
            this.moveTaskToBack(true);
            return true;
         }
        return super.onKeyDown(keyCode, event);
    }
    

    or

    If you want to close the activity use this.finish() method to close the current running activity. instead of this.moveTaskToBack(true);

提交回复
热议问题