move initDi in BaseFragment to onActivityCreated, to avoid null activityComponent when fragment is created before activity
RuiMiguel opened this issue · comments
Rui Miguel Alonso commented
Hi Sergio,
due to FragmentLifecycle and ActivityLifecycle, if you initDI on BaseFragment onCreate instead of onActivityCreated it could be possible that Fragment where created before Activity, and if you access to activityComponent from Fragment it returns null and no DI is possible.
In your code there is no problem, but I've tried it with Fragments in ViewPager in an Activity, and navigation to a DetailActivity clicking in Fragment elements. On going back, Fragment are created before activity and DI crash.