0

This code is from my Fragment1 (which creates another fragment)

currentState = currentStateFactory.factory();
Log.e("","new state = "+currentState);  
//In the log I can see currentState is not null
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
if (ft != null) {
    Log.e("","replacing");
    ft.replace(R.id.inner_container, currentState, CURRENT_STATE).commit();
}
currentState = (InitableFragment) getChildFragmentManager().findFragmentByTag(CURRENT_STATE);
Log.e("", "currentState != null check...  "+currentState);
//In the log I can see currentState is null
if (currentState != null) {
    Log.e("", "currentState initng");
    currentState.init();
}

why findFragmentByTag returns null?

ddfra
  • 2,413
  • 14
  • 24

1 Answers1

0

According to the Android developer reference:

Schedules a commit of this transaction. The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.

http://developer.android.com/reference/android/app/FragmentTransaction.html#commit()

Maybe you can move the #init() call into your Fragment's onAttach()?

Sebastian
  • 318
  • 2
  • 12