I have an Activity
which is recreated on a config change (desired). I have a DialogFragment
which calls setRetainInstance(true)
with a single EditText
in its layout.
In the DialogFragment's onActivityCreated
I call:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
A) If I open the keyboard then when I put the app into the background and then bring it to the foregournd then I want the keyboard to still be displayed.
B) If I close the keyboard (EditText still has focus and shows cursor which is desired behaviour) then I want the keyboard to still be closed if I put the app into the background and then bring it to the foreground.
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.
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.
Edit Please note that I do not want to prevent the activity from being re-created on a configuration change.
I also experimented with WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
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.