Can I override the ‘Home’ button in my application?

Override the method below.

@Override
public void onAttachedToWindow()
{  
    Log.i("TESTE", "onAttachedToWindow");
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();  
}

With this method, the HOME Button stops working in this activity (only this activity). Then you just reimplement as it was a normal button event (the back button for instance).

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        Log.i("TESTE", "BOTAO HOME");
        return true;
    }
    return super.onKeyDown(keyCode, event);    
}

Leave a Comment