1

I am in my application and I have control back button but I also want to control home button. I have written the code but I am unable to control HOME button. Here is my code. Help me to achieve it.

public boolean onKeyDown(int keyCode, KeyEvent event) 
{
  if (keyCode == KeyEvent.KEYCODE_BACK ) 
  {
    return false;
  }
  else if (keyCode == KeyEvent.KEYCODE_HOME)
  {
    return false;
  }
  return super.onKeyDown(keyCode, event);    
}
David
  • 208,112
  • 36
  • 198
  • 279
Smith
  • 413
  • 3
  • 9
  • 24
  • If you can tell why you want to override home button , we may be able to help in telling the alternative way to achieve the solution instead of overriding HOME button. – sat Mar 21 '11 at 10:54
  • @sat i just want to lock the current screen on which i am.(i.e user must not go anywhere from the screen),i have achieve it for back button,now i want to control home.please give some idea to achieve it....thanks in advance – Smith Mar 21 '11 at 11:45
  • @sat i am trying to design LOCK SCREEN software.what will be the use if user presses HOME button and is able to see main menu,this may be similar to slide unlock application in Symbian.. – Smith Mar 24 '11 at 08:50

2 Answers2

7

You cannot override the home key function, this functionality would allow an app to lock the user out of the phone.

Philio
  • 3,675
  • 1
  • 23
  • 33
2

As per Android core concepts, no application can alter the behaviour of the Home button.

This you may not achieve what you're trying to do.

EDIT

You can try to code one Home Screen Launcher so that when user presses the home button, they can go to your Home Launcher.

Aman Alam
  • 11,231
  • 7
  • 46
  • 81