Home > database >  Android back button not working after onKeyUp() is overridden
Android back button not working after onKeyUp() is overridden

Time:02-06

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    ...
    return false;
}

Once the above method is added to an activity, the back button stops working but the other two buttons on the navigation bar - home and overview - still work perfectly.

Could anyone shed some light on this?

enter image description here

CodePudding user response:

Because You're always returning false from it. It should actually be conditional & in other cases, you should call super.onKeyUp(keyCode, event);

Example:

 @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (condition == true){
            //do something
            return false;
        }
        return super.onKeyUp(keyCode,event);
    }
  •  Tags:  
  • Related