Dependence injection at fragment using dagger
Step 1 : Add to activity module @Subcomponent (modules = {ActivityModule. class }) public interface FragmentComponent { void inject(HamburgerActivity mainActivity); void inject(HomeScreenFragment homeScreenFragment); } Step 2: inject current fragment in onViewCreated @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout. com_philips_lumea_treatment_done , null ); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super .onViewCreated(view, savedInstanceState); // inject current fragment ((Application) getActivity().getApplication()).getFragmentComponent().inject( this ); } Step 3 : Register and Unregister @Override public void onStop() { super .onStop(); if ( eventing != null ) { eventing .unregister( this ); } } @Override public void onStart() { super .onStart(); if