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 e1b2fe3f5..cd524009f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -212,7 +212,8 @@ public class DelegateBase implements DlgClickNotify, protected void setResult( int result, Intent intent ) { if ( m_activity instanceof MainActivity ) { - Assert.fail(); + MainActivity main = (MainActivity)m_activity; + main.setFragmentResult( this, result, intent ); } else { m_activity.setResult( result, intent ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index a07b74ceb..4ce58d3bc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -1213,7 +1213,7 @@ public class GameConfigDelegate extends DelegateBase bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID ); bundle.putBoolean( INTENT_FORRESULT_ROWID, true ); - if ( false && delegator.inDPMode() ) { + if ( delegator.inDPMode() ) { delegator.addFragmentForResult( new GameConfigFrag(), bundle, requestCode ); } else { Activity activity = delegator.getActivity(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java index a31ee8850..d8abc7f71 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java @@ -39,6 +39,11 @@ import android.widget.FrameLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout; +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import org.eehouse.android.xw4.jni.CurGameInfo; import junit.framework.Assert; @@ -56,6 +61,10 @@ public class MainActivity extends XWActivity private int m_nextID = 0x00FFFFFF; private Boolean m_isPortrait; + // for tracking launchForResult callback recipients + private Map> m_pendingCodes + = new HashMap>(); + @Override protected void onCreate( Bundle savedInstanceState ) { @@ -215,10 +224,37 @@ public class MainActivity extends XWActivity public void addFragmentForResult( XWFragment fragment, Bundle extras, RequestCode requestCode ) { - DbgUtils.logf( "addFragmentForResult(): dropping requestCode" ); + DbgUtils.assertOnUIThread(); + + WeakReference ref + = new WeakReference(fragment.getDelegate()); + m_pendingCodes.put( requestCode, ref ); + addFragmentImpl( fragment, extras, this ); } + protected void setFragmentResult( DelegateBase delegate, int resultCode, + Intent data ) + { + DbgUtils.assertOnUIThread(); + RequestCode requestCode = null; + Iterator iter = m_pendingCodes.keySet().iterator(); + while ( iter.hasNext() ) { + RequestCode key = iter.next(); + WeakReference ref = m_pendingCodes.get(key); + DelegateBase thisOne = ref.get(); + if ( null != thisOne && thisOne.equals(delegate) ) { + requestCode = key; + iter.remove(); + break; + } + } + + if ( null != requestCode ) { + delegate.onActivityResult( requestCode, resultCode, data ); + } + } + protected void finishFragment() { getSupportFragmentManager().popBackStack();