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.
This commit is contained in:
Eric House 2017-08-29 07:31:37 -07:00
parent 741dbf2bed
commit 077159b8c4
3 changed files with 7 additions and 5 deletions

View file

@ -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;
}

View file

@ -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 );
}
//////////////////////////////////////////////////////////////////////

View file

@ -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;