简体   繁体   中英

How to ignore settings or other button function when android application is running

The question is simple, How to ignore settings or other button function when android application is running ? We have an application, everything is fine, but when we press the button (hardware on our mobile phone) the application closes with error (Unfortunately, application has stopped) We just want to ignore the settings button and close the application when the "back" (<-) button is pressed. Thank you for your answers.

In your main activity simply override onKeyDown.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK)
           finish();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM