title: Maintain keyboard open/closed state for EditText when app comes to foreground
body: <p>I have an <code>Activity</code> which is recreated on a config change (desired). I have a <code>DialogFragment</code> which calls <code>setRetainInstance(true)</code> with a single <code>EditText</code> in its layout.</p>
  
  <p>In the DialogFragment's <code>onActivityCreated</code> I call:</p>
  
  <pre><code>getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
  </code></pre>
  
  <p>A) If I open the keyboard then when I put the app into the background and then bring it to the foregournd then <strong>I want the keyboard to still be displayed</strong>.</p>
  
  <p>B) If I close the keyboard (EditText still has focus and shows cursor which is desired behaviour) then <strong>I want the keyboard to still be closed</strong> if I put the app into the background and then bring it to the foreground.</p>
  
  <p>I can't seem to achieve both A) and B). The keyboard is always closed when I bring the app to the foreground. I've tried .SOFT_INPUT_STATE_ALWAYS_VISIBLE but then the keyboard is always open. </p>
  
  <p>Thanks in advance for any suggestions as to how I might achieve this. I also wish to maintain such keyboard state across rotation but I'm leaving that for another day. Peter.</p>
  
  <p><strong>Edit</strong>
  Please note that I do <strong>not</strong> want to prevent the activity from being re-created on a configuration change.</p>
  
  <p>I also experimented with <code>WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED</code> which did maintain the keyboard open/close state during rotation on a phone (single pane layout) but a) did not work with a dual pane layout b) did not maintain the keyboard state when bringing the app to the foreground.</p>