最小化按键后的活动

时间:2011-07-08 04:56:39

标签: android minimize onkeydown

OnBack按键我想最小化应用程序,我该怎么办 此???

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

}

由于

1 个答案:

答案 0 :(得分:28)

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

这会将活动发送到后台。有关详细信息,请参阅documentation