/** * Dismiss safely regardless of the DialogFragment's life cycle. */ @Override public void dismiss() { if (!mAttached) { // dismiss() before getFragmentManager() is set cause NPE in dismissInternal(). // FragmentManager is set when a fragment is used in a transaction, // so wait here until we can dismiss safely. mDismissPending = true; } else { super.dismiss(); } }
/** * Actually dismiss the dialog fragment. */ private void superDismiss() { mCalledSuperDismiss = true; if (mActivityReady) { // The fragment is either in onStart or past it, but has not gotten to onStop yet. // It is safe to dismiss this dialog fragment. if (mAllowStateLoss) { super.dismissAllowingStateLoss(); } else { super.dismiss(); } } // If mActivityReady is false, then this dialog fragment has already passed the onStop // state. This can happen if the user hit the 'home' button before this dialog fragment was // dismissed or if there is a configuration change. // In the event that this dialog fragment is re-attached and reaches onStart (e.g., // because the user returns to this fragment's activity or the device configuration change // has re-attached this dialog fragment), because the mCalledSuperDismiss flag was set to // true, this dialog fragment will be dismissed within onStart. So, there's nothing else // that needs to be done. } }
/** * Dismisses the given <var>dialog</var>. * <p> * <b>Note</b>, that this implementation is wrapped into <b>{@code try => catch}</b> block to prevent * IllegalStateException to be raised in case, when the given dialog is in illegal state and * cannot be dismissed. * * @param dialog Instance of DialogFragment to dismiss. * @return {@code True} if dialog was successfully dismissed, {@code false} otherwise. * @see #dismissDialog(int) * @see #dismissDialog(String) */ public boolean dismissDialog(@NonNull DialogFragment dialog) { try { dialog.dismiss(); return true; } catch (IllegalStateException e) { Log.e(TAG, "Error occurred during dismissing of dialog(" + dialog + ").", e); } return false; }
/** * Dismisses the given <var>dialog</var>. * <p> * <b>Note</b>, that this implementation is wrapped into <b>{@code try => catch}</b> block to prevent * IllegalStateException to be raised in case, when the given dialog is in illegal state and * cannot be dismissed. * * @param dialog Instance of DialogFragment to dismiss. * @return {@code True} if dialog was successfully dismissed, {@code false} otherwise. * @see #dismissDialog(int) * @see #dismissDialog(String) */ public boolean dismissDialog(@NonNull DialogFragment dialog) { try { dialog.dismiss(); return true; } catch (IllegalStateException e) { Log.e(TAG, "Error occurred during dismissing of dialog(" + dialog + ").", e); } return false; }
@Override public void dismiss() { if (getFragmentManager() == null) return; super.dismiss(); }
public static void safeDismissDialog(DialogFragment dialog) { if (dialog == null || dialog.isDetached()) { return; } dialog.dismiss(); }
@Override public void onClick(View view) { Fragment prev = getFragmentManager().findFragmentByTag(FWDOWNLOAD_FRAGMENT_TAG); if (prev != null) { DialogFragment df = (DialogFragment) prev; df.dismiss(); } } });
private void closeDialogIfOpen(String tag) { FragmentManager manager = getFragmentManager(); if (manager == null) { // Do nothing if the manager doesn't exist yet; see http://crbug.com/480544. return; } DialogFragment df = (DialogFragment) manager.findFragmentByTag(tag); if (df != null) { df.dismiss(); } }
public void closeDialog() { Fragment prev = getFragmentManager().findFragmentByTag(FWDOWNLOAD_FRAGMENT_TAG); if (prev != null) { DialogFragment df = (DialogFragment) prev; df.dismiss(); } }
public static void show(Activity activity, boolean show) { String tag = "addMe"; FragmentManager fm = activity.getFragmentManager(); DialogFragment dialogFragment; if (show) { dialogFragment = new AddNoteDialog(); dialogFragment.show(fm, tag); } else { dialogFragment = (DialogFragment) fm.findFragmentByTag(tag); if (dialogFragment != null) { dialogFragment.dismiss(); } } }
public void onEventMainThread(ThrowableFailureEvent event) { if (!isInExecutionScope(executionScope, event)) { return; } checkLogException(event); // Execute pending commits before finding to avoid multiple error fragments being shown android.app.FragmentManager fm = getFragmentManager(); fm.executePendingTransactions(); android.app.DialogFragment existingFragment = (android.app.DialogFragment) fm .findFragmentByTag(TAG_ERROR_DIALOG); if (existingFragment != null) { // Just show the latest error existingFragment.dismiss(); } android.app.DialogFragment errorFragment = (android.app.DialogFragment) factory.prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog); if (errorFragment != null) { errorFragment.show(fm, TAG_ERROR_DIALOG); } }
public void onEventMainThread(ThrowableFailureEvent event) { if (!isInExecutionScope(executionScope, event)) { return; } checkLogException(event); // Execute pending commits before finding to avoid multiple error fragments being shown android.app.FragmentManager fm = getFragmentManager(); fm.executePendingTransactions(); android.app.DialogFragment existingFragment = (android.app.DialogFragment) fm .findFragmentByTag(TAG_ERROR_DIALOG); if (existingFragment != null) { // Just show the latest error existingFragment.dismiss(); } android.app.DialogFragment errorFragment = (android.app.DialogFragment) factory.prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog); if (errorFragment != null) { errorFragment.show(fm, TAG_ERROR_DIALOG); } }
public void onEventMainThread(ThrowableFailureEvent event) { if (!isInExecutionScope(executionScope, event)) { return; } checkLogException(event); // Execute pending commits before finding to avoid multiple error fragments being shown android.app.FragmentManager fm = getFragmentManager(); fm.executePendingTransactions(); android.app.DialogFragment existingFragment = (android.app.DialogFragment) fm .findFragmentByTag(TAG_ERROR_DIALOG); if (existingFragment != null) { // Just show the latest error existingFragment.dismiss(); } android.app.DialogFragment errorFragment = (android.app.DialogFragment) factory.prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog); if (errorFragment != null) { errorFragment.show(fm, TAG_ERROR_DIALOG); } }