In my app I use DialogFragments.
Some times, i am getting
Fragment already added IllegalStateException
and the app crashes. These crashes seen on crashlytics.
This problem seems to happen when trying to show the same dialog fragment twice before the first instance dismissed.
This issue already discussed many times like here or here but the problem is, that it's not constant behavior on all devices.
I couldn't reproduce this problem on my desk. Even when I try to show the same dialog twice, I am not getting this exception.
I even used fragment.isAdded()
to make sure that it is shown, and then show it again. Just to catch the error of course. but no success.
Any Idea?
I can add fragment.isAdded()
condition before showing the dialog to prevent this, but I want to understand the root cause of this. I am concerned that I cannot reproduce this.
Here is a portion of my code to show the dialog:
MyDialog
extends DialogFragment
MyDialog dialog = (MyDialog) getSupportFragmentManager().findFragmentByTag(MyDialog.TAG);
if(dialog == null) { //create and show the dialog
dialog = new MyDialog();
dialog.setCancelable(false);
}
dialog.show(getSupportFragmentManager(), MyDialog.TAG);