In android I have been able to override the functionality of back button very easily but for my app I need to override the home button
. For example the user is in Activity A
, when he presses the home button, activity B is launched
. I have tried to do the following but it failed.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
startActivity(new Intent(this, ActivityB.class));
return true;
}
return super.onKeyDown(keyCode, event);
}
I am sure it can be done because in Nova Launcher
when the user is on home screen
and he presses the home button
, the launcher offers the user a list of home screens
to jump to. I need same kind of functionality. How can this be achieved.
Regards
No you can't override the functionality of HomeButton. Its for security reasons so that malicious apps does not take control of your home button.
If you want to handle home button inplement home screen.
I am not sure if the below is helpfull.
You can Override
onUserLeaveHint
protected void onUserLeaveHint ()
if you want toTry to override this method and write your code.
Try this:
As a security feature of android, the activity only launches after 5 seconds. If you want to launch it immediately. use your own
Home Launcher
.