Inject fragments earlier in their lifecycle
Fragments are injected in Fragment#onActivityCreated()
, which is called after Fragment#onCreate()
and Fragment#onCreateView()
, meaning injected fields can't be used in those methods. It would sometimes be useful to have access to injected fields earlier in the fragment's lifecycle.
Injection happens at this point because BaseActivity creates its ActivityComponent in Activity#onCreate()
. Would it be possible for BaseFragment to create a FragmentComponent in Fragment#onCreate()
(or even Fragment#onAttach()
) to avoid this dependency on the activity to perform injection?