This question already has an answer here:
- Disable back button in android 14 answers
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
You have to override
onBackPressed()
function. Below I am giving a way:You must add return in order for this to sucessfully work on all devices, my note 3 & htc still go back if I don't include return!
This is my solution it works using Android 2.2
override onBackPressed() ...
Like if you want to move on some activity by pressing back button,override this method in your activity