avast / android-styled-dialogs

Backport of Material dialogs with easy-to-use API based on DialogFragment
Apache License 2.0
2.15k stars 450 forks source link

IllegalStateException when changing orientation with parent-Fragment as targetFragment #18

Closed mrgoltstein closed 11 years ago

mrgoltstein commented 11 years ago

Unless parent Fragment is retained, setting parent-Fragment as targetFragment will cause an IllegalStateException when changing orientation (or restoring from savedInstance), because the SimpleDialogFragment will be recreated before the parent has been restored.

This:

mBuilder.setTargetFragment((Fragment) this, mRequestCode)

Will cause:

java.lang.IllegalStateException: Fragement no longer exists for key android:target_state: index 1

Proposed solution: fallback first to parent-Fragment if no targetFragment is set, then fallback to Activity if SimpleDialogFragment has no parent-Fragment.