0

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.

enter image description here

and
  • 343
  • 1
  • 2
  • 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 Answers2

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,002
  • 9
  • 70
  • 104
0

You only need to call onBackPressed and leave empty in your activity class

@Override
public void onBackPressed() {
}
Santiago
  • 1,664
  • 14
  • 23