Consider we have an activity that in that we load a webview
. Now I want to disable the backward button in this activity whether hardware and whether software in all the android versions.
Asked
Active
Viewed 46 times
0

and
- 341
- 1
- 3
- 11
-
Possibly duplicate with many other questions in SO, such as [Disable back button in android](http://stackoverflow.com/questions/4779954/disable-back-button-in-android) – BNK Aug 24 '15 at 16:19
2 Answers
1
If you are targeting below API android.os.Build.VERSION_CODES.ECLAIR
, please do this,
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
If you are targeting higher APIs, then do this in your Activity,
@Override
public void onBackPressed() {
// Do something here or leave it blank
}
If you want to perform some operation, put some code there or just leave it blank to block back button press.

Aritra Roy
- 15,355
- 10
- 73
- 107
0
You only need to call onBackPressed and leave empty in your activity class
@Override
public void onBackPressed() {
}

Santiago
- 1,744
- 15
- 23