I use this method to hide keyboard.
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE);
View v = getActivity().getWindow().peekDecorView();
if (null != v) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
But sometimes it is throwing NullPointerException, and the keyboard is n't hiding.
sync device with java.util.concurrent.CompletionException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object androidx.fragment.app.FragmentActivity.getSystemService(java.lang.String)' on a null object reference
I have save the activity instance by override method onAttach,and use
activity.getSystemService(INPUT_METHOD_SERVICE);
but it doesn't work.