I have an Activity with have a different stack of fragments. One fragment, which has a list of items, starts an activity of detail. In this activity I need the fragment instance to do something (related to dagger 2) when the activity is created.
I have tried the findFragmentById and findFragmentByTag methods but returns null.
I have this code in my activity:
protected void initDI() {
ContactsFragment contactsFragment = (ContactsFragment) getSupportFragmentManager().findFragmentById(fragmentId);
ContactsFragmentComponent fragmentComponent = contactsFragment.getFragmentComponent();
DetailContactActivityComponent subcomponent = fragmentComponent.createSubcomponent(new DetailContactActivityModule());
subcomponent.injectDetailContactActivity(this);
}
How can I get the instance of the fragment in the activity?
EDIT:
The problem is when I start a new activity and I get the getFragmentManager instance, this instance is different from the fragmentManager of the fragment that starts the activity.