In one of the activations, the keyboard opens in this way:

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED); 

In the onStop and onPause methods I try to close it, so that when I return to another activation, it will hide. Close this:

  InputMethodManager imm = (InputMethodManager) (getSystemService(Context.INPUT_METHOD_SERVICE)); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); 

But it does not close. Where is the mistake?

    2 answers 2

    I turn off the soft keyboard like this:

     public void hideKeyboard() { InputMethodManager imm = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE); //Find the currently focused view, so we can grab the correct window token from it. View view = this.getCurrentFocus(); //If no view currently has focus, create a new one, just so we can grab a window token from it if (view == null) { view = new View(this); } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } 
    • I'm not confused, and here it is. Elaborates the onStart method of the activation to which the program returns. I checked it. But all the options for closing the keyboard, which are written here, however, do not work, I put them in this onStart method. I do not know what could be the matter. - Helena2977

    The state of the keyboard is determined for each activation separately.
    Those. You do not need to hide it in onStop or in onPause for the next activation.
    Specify attribute for activity tag in manifest

     android:windowSoftInputMode="stateHidden" 

    If you want the activation to start always with a hidden keyboard.
    Or programmatically, as you did, only in the methods of the new activation.

    As a software solution

     getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌​; 
    • there is a stateHidden, but for some reason this does not help. Maybe because the activation already exists, but not created anew. - Helena2977
    • In onStart, a new activation was attempted, but there is no focus there. What to put in the first parameter? - Helena2977
    • Yes, the manifest is used when creating the activit. - Eugene Krivenja
    • I tried this: imm.showSoftInput (getWindow (). GetDecorView (), InputMethodManager.HIDE_IMPLICIT_ONLY); did not help. - Helena2977
    • Updated the answer. But it seems to me that you are confused in your application. Reconsider the approach. - Eugene Krivenja