Don't initiate fragment transactions from onDestroy()

b/10918608

Change-Id: I649c5f86e5f77fa2ade33345969a44ffebb463b9
This commit is contained in:
Tony Mantler 2013-10-29 13:34:50 -07:00
parent edebff6db3
commit 9460be06aa
1 changed files with 18 additions and 6 deletions

View File

@ -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);
}