I have a bit complex scenario. Let me first post the code then explain FragmentModule
@Module
public class FragmentModule
{
@Provides
public static PickerDashboardFragment providesPickerDashboard()
{
PickerDashboardFragment fragment = new PickerDashboardFragment();
return fragment;
}
@Provides
public static PickingFragment providesPickingFragment()
{
PickingFragment fragment = new PickingFragment();
return fragment;
}
@Provides
public static PickingItemsFragment providesPickingItemsFragment()
{
PickingItemsFragment fragment = new PickingItemsFragment();
return fragment;
}
**Note this**
@Provides
public static StagedItemsFragment providesStagedItemsFragment(ArrayList<PickJava> pickedList)
{
Bundle arguments = new Bundle();
arguments.putParcelableArrayList("picked_list", pickedList);
StagedItemsFragment fragment = new StagedItemsFragment();
return fragment;
}
}
Here is FragmentComponent
@Component(modules = {FragmentModule.class, FragmentUtilsModule.class})
public interface FragmentComponent
{
void inject(PickerDashboardActivity target);
void inject(PickerDashboardFragment target);
void inject(PickingFragment target);
**Note this**
StagedItemsFragment stagedItemsFragment();
}
Very important part. Requesting injection and this is how i'm building my component inside Fragment.
public class PickingFragment extends Fragment{
FragmentComponent component
@Inject
PickingItemsFragment pickingItemsFragment;
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
component = DaggerFragmentComponent
.builder()
.fragmentUtilsModule(new FragmentUtilsModule(this))
.build();
component.inject(this);
}
**Note this**
@Override
public void onClick(View v)
{
// Here i need StagedItemsFragment stagedItemsFragment(); from FragmentComponent
replaceNestedFragment(component.stagedItemsFragment());
}
But the problem is that the fragmentComponent is already built. Now as you can see in the FragmentModule
providesStagedItemsFragment
method requires ArrayList<PickJava> pickedList
as a argument. How can i pass this. Please help or ask more details if required.