title: I can't hide the virtual keyboard on Android
body: <p>I am working with fragments and nesting fragments within fragments using the support library. </p>
  
  <p>I have a scenario where I add a new fragment (which contains an EditText) from within the existing fragment. When the user taps on the EditText a virtual keyboard is shown. But while the keyboard is open the user can press the home button from the ActionBar which removes the fragment from the stack, but the keyboard still remains open. I can not force a close on the keyboard, I tried all code snippets. Given the described scenario, can anyone guide me as to how can I solve this ?</p>
  
  <p>EDIT: I made a callback function which I call from the fragments onDestroy. The MainActivity which hosts all fragments implements this callback:</p>
  
  <pre><code>@Override
  public void onHideSoftKeyboard(EditText editText) {
      // HIDE SOFT KEYBOARD HERE 
  
  final InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
  
       Toast.makeText(this,"KEYBOARD HIDDEN",Toast.LENGTH_LONG).show();
  }
  </code></pre>
  
  <p>I get the Toast message and the fragment is destroyed on the back button (ActionBar back button), only the keyboard is still present.</p>
  
  <pre><code>@Override
  public void onDestroy() {
      hideSoftKeyboard.onHideSoftKeyboard(editTextComment);
  
  
  
      super.onDestroy();
  }
  </code></pre>