Disable back button in android
Override the onBackPressed method and do nothing if you meant to handle the back button on the device.
@Override
public void onBackPressed() {
if (shouldAllowBack()) {
super.onBackPressed();
} else {
doSomething();
}
}
If looking for a higher api level 2.0 and above this will work great
@Override
public void onBackPressed() {
// Do Here what ever you want do on back press;
}
If looking for android api level upto 1.6.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
Write above code in your Activity to prevent back button pressed
You can do this simple way Don't call super.onBackPressed()
Note:- Don't do this unless and until you have strong reason to do it.
@Override
public void onBackPressed() {
// super.onBackPressed();
// Not calling **super**, disables back button in current screen.
}