I've an Activity that extends AppCompatActivity
.
I tried to disable back button like this:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
}
return true;
}
@Override
public void onBackPressed() {
Toast.makeText(this, "Back pressed", Toast.LENGTH_LONG).show();
}
I get the Toast
which is good sign, but bad sign is, that it finishes activity and goes to the previous one (I'd like to avoid that).