-// searchText.postDelayed(new Runnable() {
-// @Override
-// public void run() {
-// Log.d(LOG, "Trying to show soft keyboard.");
-// final boolean searchTextHadFocus = searchText.hasFocus();
-// searchText.requestFocus();
-// final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-// manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
-// if (!searchTextHadFocus) {
-// defocusSearchText();
-// }
-// }}, 100);
+ // For some reason, this doesn't always work the first time.
+ // One way to replicate the problem:
+ // Press the "task switch" button repeatedly to pause and resume
+ for (int delay = 1; delay <= 101; delay += 100) {
+ searchView.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.d(LOG, "Trying to show soft keyboard.");
+ final boolean searchTextHadFocus = searchView.hasFocus();
+ searchView.requestFocusFromTouch();
+ final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ manager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
+ if (!searchTextHadFocus) {
+ defocusSearchText();
+ }
+ }}, delay);
+ }