There are many questions discussing an issue where DialogFragment disappears on device rotation. But I have an opposite one. I have to rotate the device to force dialog to appear.
I am using the android-support-v4.jar lib.
I have MainActivity (android.support.v4.app.FragmentActivity
) with AccountsFragment (android.support.v4.app.Fragment
).
Via menu item the user triggers showing SettingsDialogFragment (android.support.v4.app.DialogFragment
).
The SettingsDialogFragment is shown from within MainActivity using:
android.support.v4.app.DialogFragment.show(FragmentManager manager, String tag)
FragmentManageer is got form MainActivity using:
android.support.v4.app.FragmentActivity.getSupportFragmentManager()
User clicks a button on SettingsDialogFragment that triggers showing PasslockSetupActivity (android.support.v4.app.FragmentActivity
).
User finishes with pass lock setup, we call PasslockSetupActivity.finish().
Expected result: user should see SettingsDialogFragment over MainActivity with AccountsFragment. Actual result: user sees MainActivity with AccountsFragment (no dialog!)
Observations:
- If "Don't keep acvitivies" developer options is enabled on device, then it works as expected.
- If user rotates device, then the dialog does appear!
Both observations tell that if system re-creates MainActivity, then it successfully restores the dialog too.
Also, I reproduce only on Android 4.2.1/4.2.2. Other versions seem to be OK.
Has anyone encountered such an issue? Any ideas?
UPDATE:
Just realized that I can reproduce the issue even without starting another activity! It's just enough to click Home button, so the app goes to background, and then pick the app from the list of recent apps, so it appears back to foreground. Dialog is gone. But if I rotate device, the dialog becomes shown.