I have found a workaround. It is extremely ugly, but it works.
So here is how I was able to restore the search box instance state after a configuration change.
First of all, restore the query string in onRestoreInstanceState
currentQuery = state.getString(KEY_SAVED_FILTER_CONSTRAINT);
In onCreateOptionsMenu set up the search view and if there is a currentQuery, expand the search item and submit the query again. Clear the focus to hide the keyboard.
MenuItem searchItem = menu.findItem(R.id.action_search);
searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
if (!TextUtils.isEmpty(currentQuery)) {
searchItem.expandActionView();
searchView.setQuery(currentQuery, true);
searchView.clearFocus();
}
Finally we need to close the suggestion list. Here is how to get the query text view from the search view:
private AutoCompleteTextView findQueryTextView(ViewGroup viewGroup) {
AutoCompleteTextView queryTextView = null;
if (viewGroup != null) {
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof AutoCompleteTextView) {
queryTextView = (AutoCompleteTextView) child;
break;
} else if (child instanceof ViewGroup) {
queryTextView = findQueryTextView((ViewGroup) child);
if (queryTextView != null) {
break;
}
}
}
}
return queryTextView;
}
Then you can dismiss the suggestion list:
AutoCompleteTextView queryTextView = findQueryTextView(searchView);
if (queryTextView != null) {
queryTextView.dismissDropDown();
}
This does however not work from within onCreateOptionsMenu. I had to move the invocation of dismissDropDown into the onNewIntent method of my activity to make it work.
What makes this so ugly is the fact that the restoration steps are dispersed over various phases of the lifecycle and that a recursive view search is necessary to get to the suggestion list.