From 5b4e04bc5ad342f0e87dc706ac86a7f35bb43412 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 20 Jul 2016 08:58:34 -0700 Subject: [PATCH] fix fragment exception launching after dict download create queue of Runnables to be run only when Delegate is visible (onResume() has been called and onPause() hasn't.) When missing dict finishes downloading, rather than immediately opening its game, post a Runnable to do it that will be run only after the main activity is ready to have fragment transactions committing again. --- .../org/eehouse/android/xw4/DelegateBase.java | 19 +++++++++++++++++++ .../android/xw4/GamesListDelegate.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java index cd524009f..3fbd3a0b6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -38,6 +38,7 @@ import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; +import java.util.ArrayList; import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; @@ -58,6 +59,7 @@ public class DelegateBase implements DlgClickNotify, private int m_layoutID; private View m_rootView; private boolean m_isVisible; + private ArrayList m_visibleProcs = new ArrayList(); public DelegateBase( Delegator delegator, Bundle bundle, int layoutID ) { @@ -116,6 +118,7 @@ public class DelegateBase implements DlgClickNotify, { m_isVisible = true; XWService.setListener( this ); + runIfVisible(); } protected void onPause() @@ -274,6 +277,16 @@ public class DelegateBase implements DlgClickNotify, return result; } + private void runIfVisible() + { + if ( isVisible() ) { + for ( Runnable proc : m_visibleProcs ) { + post( proc ); + } + m_visibleProcs.clear(); + } + } + protected String getString( int resID, Object... params ) { return LocUtils.getString( m_activity, resID, params ); @@ -601,6 +614,12 @@ public class DelegateBase implements DlgClickNotify, return false; // not handled } + protected void runWhenActive( Runnable proc ) + { + m_visibleProcs.add( proc ); + runIfVisible(); + } + ////////////////////////////////////////////////// // MultiService.MultiEventListener interface ////////////////////////////////////////////////// diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 0b3b0bc65..da3cc9843 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -1595,7 +1595,7 @@ public class GamesListDelegate extends ListDelegateBase public void downloadFinished( String lang, String name, final boolean success ) { - post( new Runnable() { + runWhenActive( new Runnable() { public void run() { boolean madeGame = false; if ( success ) {