Skip to content

Commit

Permalink
ClassifyActivity: Delay the AlertDialog until onResumeFragments().
Browse files Browse the repository at this point in the history
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 012b88c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/com/murrayc/galaxyzoo/app/ClassifyActivity.java
Expand Up @@ -55,6 +55,8 @@ public class ClassifyActivity extends ItemActivity
ClassifyFragment.Callbacks, QuestionFragment.Callbacks{
private boolean mIsStateAlreadySaved = false;
private boolean mPendingClassificationFinished = false;
private boolean mPendingWarnAboutNetworkProblemWithRetry = false;

private AlertDialog mAlertDialog = null;


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

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

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

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 012b88c

Please sign in to comment.