Permalink
Browse files

ClassifyActivity: Delay the AlertDialog until onResumeFragments().

When necessary, to avoid this:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  • Loading branch information...
murraycu committed Jan 9, 2015
1 parent 52004d2 commit 012b88c13d9f082fc99d0dee9e5b196f94ff5d60
Showing with 21 additions and 0 deletions.
  1. +21 −0 app/src/main/java/com/murrayc/galaxyzoo/app/ClassifyActivity.java
@@ -55,6 +55,8 @@
ClassifyFragment.Callbacks, QuestionFragment.Callbacks{
private boolean mIsStateAlreadySaved = false;
private boolean mPendingClassificationFinished = false;
private boolean mPendingWarnAboutNetworkProblemWithRetry = false;

private AlertDialog mAlertDialog = null;


@@ -315,6 +317,13 @@ protected void onResumeFragments() {
return;
}

//See warnAboutNetworkProblemWithRetry().
if(mPendingWarnAboutNetworkProblemWithRetry) {
mPendingWarnAboutNetworkProblemWithRetry = false;
doWarnAboutNetworkProblemWithRetry();
return;
}

final ClassifyFragment fragmentClassify = getChildFragment();
if (fragmentClassify != null) {

@@ -432,6 +441,18 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,

@Override
public void warnAboutNetworkProblemWithRetry() {
// Avoid causing this exception when we try to show() an AlertDialog:
// java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
if (mIsStateAlreadySaved) {
//Do it later instead.
this.mPendingWarnAboutNetworkProblemWithRetry = true;
return;
}

doWarnAboutNetworkProblemWithRetry();
}

private void doWarnAboutNetworkProblemWithRetry() {
//Dismiss any existing dialog:
if (mAlertDialog != null) {
mAlertDialog.dismiss();

0 comments on commit 012b88c

Please sign in to comment.