Java Code Examples for android.support.v4.app.fragmentmanager#isDestroyed()

The following examples show how to use android.support.v4.app.fragmentmanager#isDestroyed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDialogFragment.java    From android-skeleton-project with MIT License 6 votes vote down vote up
public void displayDialog(BaseActivity activity, String tag) {
    if (activity == null || !activity.isActive()) {
        return;
    }

    FragmentManager fragmentManager = activity.getSupportFragmentManager();

    if (fragmentManager == null || fragmentManager.isDestroyed()) {
        return;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment oldDialog = fragmentManager.findFragmentByTag(tag);
    if (oldDialog != null) {
        transaction.remove(oldDialog);
    }
    transaction.addToBackStack(null);

    //fix for IllegalStateException: Can not perform this action after onSaveInstanceState
    //http://stackoverflow.com/questions/15729138/on-showing-dialog-i-get-can-not-perform-this-action-after-onsaveinstancestate
    if (!activity.isActive()) { //final safeguard in case activity was closed in the middle
        return;
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();
    this.show(ft, tag);
}
 
Example 2
Source File: BasePopupDialog.java    From android-skeleton-project with MIT License 6 votes vote down vote up
public void displayDialog(BaseActivity activity) {
    if (activity == null || !activity.isActive()) {
        return;
    }

    FragmentManager fragmentManager = activity.getSupportFragmentManager();

    if (fragmentManager == null || fragmentManager.isDestroyed()) {
        return;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment oldDialog = fragmentManager.findFragmentByTag(BasePopupDialog.FRAGMENT_TAG);
    if (oldDialog != null) {
        transaction.remove(oldDialog);
    }
    transaction.addToBackStack(null);

    //fix for IllegalStateException: Can not perform this action after onSaveInstanceState
    //http://stackoverflow.com/questions/15729138/on-showing-dialog-i-get-can-not-perform-this-action-after-onsaveinstancestate
    if (!activity.isActive()) { //final safeguard in case activity was closed in the middle
        return;
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();
    this.show(ft, BasePopupDialog.FRAGMENT_TAG);
}
 
Example 3
Source File: ConnectorFragment.java    From robocar with Apache License 2.0 5 votes vote down vote up
private static ConnectorFragment get(FragmentManager fm) {
    if (fm.isDestroyed()) {
        throw new IllegalStateException("Can't get fragment after onDestroy");
    }

    Fragment fragment = fm.findFragmentByTag(FRAGMENT_TAG);
    if (fragment != null && !(fragment instanceof ConnectorFragment)) {
        throw new IllegalStateException("Unexpected fragment instance was returned by tag");
    }
    return (ConnectorFragment) fragment;
}
 
Example 4
Source File: ActionSheet.java    From android-ActionSheet with MIT License 5 votes vote down vote up
public void show(final FragmentManager manager, final String tag) {
    if (!mDismissed || manager.isDestroyed()) {
        return;
    }
    mDismissed = false;
    new Handler().post(new Runnable() {
        public void run() {
            FragmentTransaction ft = manager.beginTransaction();
            ft.add(ActionSheet.this, tag);
            ft.addToBackStack(null);
            ft.commitAllowingStateLoss();
        }
    });
}