[转] DialogFragment Fragment already added

Original address: http://blog.csdn.net/u012987382/article/details/46984053 The

phenomenon
calls two interfaces asynchronously, sharing a loading progress frame (DialogFragment), the former loading frame has not been dismissed, and the latter one has started to show. A "Fragment already added" runtime exception will appear.

Solution
Before displaying the Fragment, determine whether the previous Fragment is in the displayed state.
if(!mDialogFragment.isAdded()
    && !mDialogFragment.isVisible()
    && !mDialogFragment.isRemoving()) {
    mDialogFragment.show(getFragmentManager().beginTransaction(),"normal_custom_progress_dialog");
}

illustrate
public final boolean isAdded()
If the Fragment object was added to its Activity, it returns true, otherwise it returns false.

public final boolean isRemoving()
Returns true if the current Fragment object is being removed from its Activity. This deletion process is not the end process of the Fragment object's Activity, but the process of deleting the Fragment object from its Activity.

public final boolean isVisible()
Returns true if the Fragment object is visible to the user.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326072871&siteId=291194637