问题
I'm experiencing strange, perhaps version-specific behavior with my DialogFragment subclass when testing the following steps:
(1) Open the dialog
(2) Leave the app with either the Home key or the Recent Apps key
(3) Return to the app, and the dialog is no longer visible. It seems to be briefly, translucently visible behind the main activity.
(4) Rotate the device, and the dialog re-appears.
This bug occurs on my Asus TF700T pad running Android 4.2.1, and it does not occur on my Motorola Razr phone running Android 4.1.2 (which has a menu key rather than an overflow button). Moreover, it only occurs if the dialog is opened via the overflow menu - dialogs opened via ActionBar items do not exhibit this issue! And finally, the issue does not occur if you do an orientation change before pausing the activity.
I have found a very similar issue which includes depressing comments like "This is clearly an Android bug." There are associated bug reports. Please, say it ain't so...
My workaround for this issue is in onResume(): I check the FragmentManager for existing dialogs with findFragmentByTag; if any are not null I dismiss and re-show them. But I'd like to understand what's really going on here.
回答1:
I guess the answer to this question is the Google bug report linked above. I changed my design to avoid the problem, so I have not tried the workaround someone there has posted.
来源:https://stackoverflow.com/questions/18730141/dialogfragment-behaves-differently-when-invoked-via-actionbar