I get a null pointer exception at this row:
public void hideKeyboard(){
InputMethodManager inputManager = (InputMethodManager)
this.
This works for me. Simply add the getWindow().getDecorView().getRootView().getWindowToken() following instead of using getCurrectFocus(). After that You can use this method for any where in your activity.
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager =
(InputMethodManager) activity.getSystemService(
Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
activity.getWindow().getDecorView().getRootView().getWindowToken(), 0);
}