Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize activity on back key press

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

like image 207
Sandy Avatar asked Jul 08 '11 04:07

Sandy


1 Answers

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.

like image 182
Adil Soomro Avatar answered Oct 21 '22 11:10

Adil Soomro