Stack Exchange
Keyboard is not getting hidden while my app is moving in background in Marshmallow
Keyboard is not getting hidden while my app is moving in background in Marshmallow and some android OS. Here's my code
InputMethodManager imm = (InputMethodManager)
                getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromInputMethod(getWindow().getCurrentFocus()
                .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);


try this
if(getCurrentFocus() != null) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}

