Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android back button not working after onKeyUp() is overridden

@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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading