OnBackPressed with a SoftKeyboard open
I want to finish an activity when the soft keyboard is open, I want to override the back event of the soft keyboard and finish the activity. I'm using this but it's not working , any Idea ? public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { this.finish(); return false; } return super.dispatchKeyEvent(event); } onKeyDown() and onBackPressed() doesn't work for this case. You have to use onKeyPreIme . Initially, you have to create custom edit text that extends EditText . And then you have to implement