diff --git a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java index 474d7b971..1309dff77 100644 --- a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java @@ -193,8 +193,12 @@ public class AccountCheckSettingsFragment extends Fragment { Utility.cancelTaskInterrupt(mAccountCheckTask); mAccountCheckTask = null; } - // Make doubly sure that the dialog is gone before we're removed from the fragment manager - recoverAndDismissCheckingDialog(); + // Make doubly sure that the dialog isn't pointing at us before we're removed from the + // fragment manager + final Fragment f = getFragmentManager().findFragmentByTag(CheckingDialog.TAG); + if (f != null) { + f.setTargetFragment(null, 0); + } } /** @@ -312,6 +316,9 @@ public class AccountCheckSettingsFragment extends Fragment { getFragmentManager().findFragmentByTag(CheckingDialog.TAG); } if (mCheckingDialog != null) { + // TODO: dismissAllowingStateLoss() can cause the fragment to return later as a zombie + // after the fragment manager restores state, if it happens that this call is executed + // after the state is saved. Figure out a way to clean this up later. b/11435698 mCheckingDialog.dismissAllowingStateLoss(); mCheckingDialog = null; } @@ -700,8 +707,6 @@ public class AccountCheckSettingsFragment extends Fragment { if (mProgressString == null) { mProgressString = getProgressString(getTargetRequestCode()); } - final AccountCheckSettingsFragment target = - (AccountCheckSettingsFragment) getTargetFragment(); final ProgressDialog dialog = new ProgressDialog(context); dialog.setIndeterminate(true); @@ -712,7 +717,12 @@ public class AccountCheckSettingsFragment extends Fragment { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); - target.onCheckingDialogCancel(); + + final AccountCheckSettingsFragment target = + (AccountCheckSettingsFragment) getTargetFragment(); + if (target != null) { + target.onCheckingDialogCancel(); + } } }); return dialog; @@ -726,7 +736,9 @@ public class AccountCheckSettingsFragment extends Fragment { public void onCancel(DialogInterface dialog) { final AccountCheckSettingsFragment target = (AccountCheckSettingsFragment) getTargetFragment(); - target.onCheckingDialogCancel(); + if (target != null) { + target.onCheckingDialogCancel(); + } super.onCancel(dialog); }