I override the home button like this :
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_HOME:
System.out.println("hello");
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
I create also a search interface like :
http://www.edumobile.org/android/android-programming-tutorials/search-interface/
When I click on the search hardware button, the search interface comes up. But at the same time when I click on the home button, the overridden method for Home button is not called, and I go back to main screen of phone. Can you help me how can I fix it?
You can not catch the Home-Button presses, see this question on SO for further details. In short: It is a system key, your application can not handle it on its own because it would allow a application to prevent the user from exiting it.