how to disable back button in android [duplicate]

2019-01-19 11:46发布

This question already has an answer here:

i am making swap application... i want to disable back button. so i use this code... and passed intent in to it..

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // do something on back.
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

but while running when i press back button on emulator it updates activity but when i repress back button it switch to the home page of an emulator.. please suggest is their any other method

7条回答
相关推荐>>
2楼-- · 2019-01-19 12:17

Did you try onBackPressed() ?

@Override
public void onBackPressed() {
       // Do as you please
}
查看更多
登录 后发表回答