Minimize activity on back key press

北城以北 提交于 2019-12-10 03:26:38

问题


OnBack Key press i want to minimize the application, How can i do this???

public boolean onKeyDown(int keyCode, KeyEvent event) {

   if (keyCode == KeyEvent.KEYCODE_BACK) {

           //Here i want to put minimize code.. pls give me this statement

       return true;
   }
   return super.onKeyDown(keyCode, event);

}

Thanks


回答1:


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);
    }

This will send the activity to the background. See documentation for further reference.



来源:https://stackoverflow.com/questions/6620127/minimize-activity-on-back-key-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!