How not to allow the keyboard to close when you press the back button or OK?

I tried the following action:

EditText yourEditText= (EditText) findViewById(R.id.ed); InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); 

with these options:

  1. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
  2. imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
  3. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
  • Why do I need a keyboard after Ok and Back ? Just wondering. The user did / did not do what he wanted. With these actions, he clearly indicates this. - TimurVI
  • I need the Back button to immediately immediately return to the previous activity - abrutsze
  • Override the onBackPressed() method in onBackPressed() . - eugeneek
  • Tried, does not help - abrutsze
  • show how you redefined it. - Sviat Volkov

1 answer 1

If you need, when you press the " Back " button, the transition to the previous activation is completed and the keyboard remains on the screen. That is the easiest way in the onResume this previous activation to re-show the keyboard.

 EditText editText= (EditText) findViewById(R.id.ed); InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, 0); editText.requestFocus(); 

And in order not to press the " Back " button twice, redefine onBackPressed to clean the stack of activities and start the desired activity through the intensity.