save commit id in fragment

This commit is contained in:
Eric House 2017-08-29 07:03:52 -07:00
parent 270df00692
commit bb4c5502c8
2 changed files with 9 additions and 4 deletions

View file

@ -453,14 +453,14 @@ public class MainActivity extends XWActivity
return frag;
}
private void addFragmentImpl( Fragment fragment, Bundle bundle,
private void addFragmentImpl( XWFragment fragment, Bundle bundle,
String parentName )
{
fragment.setArguments( bundle );
addFragmentImpl( fragment, parentName );
}
private void addFragmentImpl( final Fragment fragment,
private void addFragmentImpl( final XWFragment fragment,
final String parentName )
{
if ( m_safeToCommit ) {
@ -497,7 +497,7 @@ public class MainActivity extends XWActivity
}
}
private void safeAddFragment( Fragment fragment, String parentName )
private void safeAddFragment( XWFragment fragment, String parentName )
{
Assert.assertTrue( m_safeToCommit );
String newName = fragment.getClass().getSimpleName();
@ -505,10 +505,11 @@ public class MainActivity extends XWActivity
popUnneeded( fm, newName, parentName );
fm.beginTransaction()
int ID = fm.beginTransaction()
.add( R.id.main_container, fragment, newName )
.addToBackStack( newName )
.commit();
fragment.setCommitID( ID );
// Don't do this. It causes an exception if e.g. from fragment.start()
// I wind up launching another fragment and calling into this code
// again. If I need executePendingTransactions() I'm doing something

View file

@ -45,6 +45,7 @@ abstract class XWFragment extends Fragment implements Delegator {
private DelegateBase m_dlgt;
private String m_parentName;
private boolean m_hasOptionsMenu = false;
private int m_commitID;
private static Set<XWFragment> sActiveFrags = new HashSet<XWFragment>();
public static XWFragment findOwnsView( View view )
@ -75,6 +76,9 @@ abstract class XWFragment extends Fragment implements Delegator {
return m_parentName;
}
public void setCommitID( int id ) { m_commitID = id; }
public int getCommitID() { return m_commitID; }
protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu )
{
m_hasOptionsMenu = hasOptionsMenu;