Keyboard disappears on orientation change
<p>I have a fragment with EditText and add it into the layout using transactions. But if I rotate to landscape the soft keyboard disappears.</p>

<pre><code>public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (getSupportFragmentManager().findFragmentById(R.id.fragmentContainer) == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragmentContainer, new FragmentWithEditText())
                    .commit();
        }
    }
}
</code></pre>

<p>I want keyboard state still unchanged after rotate using fragment transactions. Because if I don't use transactions, but add a fragment straight in the layout, the keyboard not disappeared.</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" &gt;

    &lt;fragment
        android:tag="fragmentWithKeyboard"
        android:name="com.test.FragmentWithEditText"
        android:layout_width="match_parent"
        android:layout_height="match_parent" /&gt;

&lt;/FrameLayout&gt;
</code></pre>

<p>I already tried to use <code>android:windowSoftInputMode="stateUnchanged"</code> or <code>android:configChanges="keyboardHidden|orientation"</code>, but didn't help.</p>

<p>Also I wrote a sample app with this behavior <a href="https://github.com/anton9088/FragmentAndKeyboard" rel="noreferrer">https://github.com/anton9088/FragmentAndKeyboard</a></p>

<p><strong>Similar questions:</strong></p>

<p><a href="https://stackoverflow.com/questions/18182749/retain-soft-input-ime-state-on-orientation-change">Retain soft-input/IME state on Orientation change</a></p>

<p><a href="https://stackoverflow.com/questions/39173171/keyboard-dismissed-on-rotation-to-landscape-mode-android">Keyboard dismissed on rotation to landscape mode Android</a></p>