public void callFragmentOnCreate() { assertFragmentManager(); for (Fragment each : mfragmentManager.getFragments() .values()) { ShadowFragment shadow = Robolectric.shadowOf(each); Bundle savedInstanceState = shadow.getSavedInstanceState(); each.onCreate(savedInstanceState); } }
public void addFragment(int containerViewId, String tag, Fragment fragment, boolean replace) { fragmentsById.put(containerViewId, fragment); fragmentsByTag.put(tag, fragment); ShadowFragment shadowFragment = shadowOf(fragment); shadowFragment.setTag(tag); shadowFragment.setContainerViewId(containerViewId); shadowFragment.setShouldReplace(replace); shadowFragment.setActivity(activity); fragment.onAttach(activity); fragment.onCreate(shadowFragment.getSavedInstanceState()); }
public void callFragmentOnActivityCreated() { assertFragmentManager(); for (Fragment each : mfragmentManager.getFragments() .values()) { ShadowFragment shadow = Robolectric.shadowOf(each); Bundle savedInstanceState = shadow.getSavedInstanceState(); View view = each.onCreateView(each.getActivity() .getLayoutInflater(), null, savedInstanceState); shadow.setView(view); each.onViewCreated(view, null); each.onActivityCreated(savedInstanceState); } }
public void startFragment(Fragment fragment) { ViewGroup container = null; ShadowFragment shadowFragment = shadowOf(fragment); if (shadowOf(activity).getContentView() != null) { container = (ViewGroup) activity.findViewById(shadowFragment.getContainerViewId()); } View view = fragment.onCreateView(activity.getLayoutInflater(), container, shadowFragment.getSavedInstanceState()); shadowFragment.setView(view); fragment.onViewCreated(view, null); if (container != null) { if (shadowFragment.getShouldReplace()) { container.removeAllViews(); } if (view != null) { container.addView(view); } } fragment.onActivityCreated(shadowFragment.getSavedInstanceState()); fragment.onStart(); }