From 077159b8c4e391db5db284ca4ecd8e7bd527862a Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 29 Aug 2017 07:31:37 -0700 Subject: [PATCH] save commitID in instanceState When the back stack is restored commit() is not called, so the fragment needs to save it. Without this 0 is passed to popBackStack() and everything's dismissed, not just the one fragment. --- .../src/main/java/org/eehouse/android/xw4/DelegateBase.java | 3 +-- .../src/main/java/org/eehouse/android/xw4/MainActivity.java | 6 +++--- .../src/main/java/org/eehouse/android/xw4/XWFragment.java | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java index 648896360..5b9f4da1b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java @@ -290,8 +290,7 @@ public class DelegateBase implements DlgClickNotify, if ( main.inDPMode() ) { if ( !m_finishCalled ) { m_finishCalled = true; - XWFragment fragment = (XWFragment)m_delegator; - main.finishFragment( fragment.getCommitID() ); + main.finishFragment( (XWFragment)m_delegator ); } handled = true; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java index 72009ddcd..d4142fc47 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java @@ -298,12 +298,12 @@ public class MainActivity extends XWActivity resultCode, data ); } - protected void finishFragment( int commitID ) + protected void finishFragment( XWFragment fragment ) { - // Assert.assertTrue( fragment instanceof XWFragment ); // Log.d( TAG, "finishFragment()" ); + int ID = fragment.getCommitID(); getSupportFragmentManager() - .popBackStack( commitID, FragmentManager.POP_BACK_STACK_INCLUSIVE ); + .popBackStack( ID, FragmentManager.POP_BACK_STACK_INCLUSIVE ); } ////////////////////////////////////////////////////////////////////// diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java index d13e724b1..db4b076c7 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java @@ -41,6 +41,7 @@ import junit.framework.Assert; abstract class XWFragment extends Fragment implements Delegator { private static final String TAG = XWFragment.class.getSimpleName(); private static final String PARENT_NAME = "PARENT_NAME"; + private static final String COMMIT_ID = "COMMIT_ID"; private DelegateBase m_dlgt; private String m_parentName; @@ -91,6 +92,7 @@ abstract class XWFragment extends Fragment implements Delegator { Log.d( TAG, "%s.onSaveInstanceState() called", getClass().getSimpleName() ); Assert.assertNotNull( m_parentName ); outState.putString( PARENT_NAME, m_parentName ); + outState.putInt( COMMIT_ID, m_commitID ); m_dlgt.onSaveInstanceState( outState ); super.onSaveInstanceState( outState ); } @@ -102,6 +104,7 @@ abstract class XWFragment extends Fragment implements Delegator { if ( null != sis ) { m_parentName = sis.getString( PARENT_NAME ); Assert.assertNotNull( m_parentName ); + m_commitID = sis.getInt( COMMIT_ID ); } Assert.assertNull( m_dlgt ); m_dlgt = dlgt;