Android Hide Virtual Keyboard through code

In most situation we are in need to force close the keyboard by pressing the back button. But this can also be done using the following code.
[sourcecode language="java"]
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditTextName.getWindowToken(), 0);
[/sourcecode]

This key code forces the keyboard to close.