Added safety check on hide keyboard to fix a crash on Android.