Similar question has already appeared several times, but I have found strange regularity which I think should not occur.
There is Activity
with EditText
in its layout. When user clicks on that field, soft input appears. With flag android:windowSoftInputMode="stateUnchanged"
added to AndroidManifest
, everything works as expected on device orientation changes - keyboard retains its state. But when there is Fragment
on top of that Activity
and EditText
is located in the Fragment
it does not work. I assume that flag on AndroidManifest
is skipped in this case (flag covers only Activity
), and during orientation changes keyboard disappears.
I did not found clean solution for retaining keyboard state on orientation change. I saw solution with manually showing keyboard on onActivityCreated()
, but I do not like it as it requires to hold keyboard visibility state on some variable in object which survives orientation changes.
What I found is that if there is EditText
in Activity
, even when user does not touch it, and it is not focused, keyboard retains its state, which is totally unexpected.
I cannot remove Fragment
and rely only on Activity
because Fragments
are used in ViewPager
. But I have checked that this happens also when the Fragment
is directly attached to the Activity
.
I also found that all applications I've checked, solved that problem somehow.
Is there a clean solution for retaining keyboard state on orientation changes with fragments?
Edit: I also dislike the android:configChanges="orientation|screenSize"
option.