How to close the Android keyboard when switching activities/tabs
android, android-activity, keyboard
Solution
From Comment
`onStop()` won't be called when you switch the Tab. Use `onPause()` instead.
Problem
I have created a method to check if the keyboard is used in an activity(tab) with the editText: searchfield. Whenever I leave the activity(tab) and switches to another one, I want to close the keyboard. Therefor I call the method in onStop(). But nothing happens, why is this not working, anyone with more insights on how onStop() works in Android? How can I make it work? /Thanx alot! ``` @Override protected void onStop() { super.onStop(); this.hideKeyboard(); <---------------------- if(this.data != null) { this.data.destroy(); } } private void hideKeyboard() { if (this.searchField != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(this.searchField.getWindowToken(), 0); } } ```