title: Is there a better way to restore SearchView state?
body: <p>I have a collapsible <code>SearchView</code> in my <code>ActionBar</code>. After a search has been performed, the associated <code>ListView</code> is filtered to show only matching items. During that state, the <code>SearchView</code> is still expanded and shows the search string. If the user closes the <code>SearchView</code>, I remove the filter.</p>
  
  <p>I want to restore the search state, e.g. on configuration change or if the activity was destroyed when I return to it from another activity.</p>
  
  <p>I restore the query string in <code>onRestoreInstanceState()</code>, and if I find a query string in <code>onCreateOptionsMenu()</code> I call </p>
  
  <pre><code>searchView.setQuery(query, true); 
  </code></pre>
  
  <p>so as to execute the query again. It turned out that this is better than applying the query filter immediately <code>onRestoreInstanceState()</code>. With the latter the list is shortly shown unfiltered, only then the query is applied again. With <code>setQuery()</code> this does not happen.</p>
  
  <p>Problem: The query is executed and the list is filtered, but the search view remains collapsed. Therefore the user cannot use the search view to remove the filter or to apply another query.</p>
  
  <p>In <code>onCreateOptionsMenu()</code> I can be sure that the search item and the search view exists, therefore I can call <code>searchItem.expandActionView()</code>. Strangely, only this really expands the <code>ActionView</code> - calling <code>setIconified(false)</code> does not expand the view, not even when it is called twice in a row.</p>
  
  <p>If I use <code>expandActionView()</code> before I call <code>setQuery()</code>, the <code>SearchView</code> is opened and shows the text (otherwise <code>expandActionView()</code> empties the <code>SearchView</code>). </p>
  
  <p>Unfortunately, <code>expandActionView()</code> has a side effect: the suggestion list is also shown and the keyboard opens. </p>
  
  <p>I can hide the keyboard using <code>searchView.clearFocus()</code>. So the remaining problem is the suggestion list. How can I close an open suggestion list on a <code>SearchView</code> that has text?</p>
  
  <p>I wonder if there is a better way to restore a search view in the action bar that does not have so many side effects.</p>