having a problem with Navigation Advanced Sample provided by Google developers. Main problem is that in regular case senario for Hilt dependency injection we can simply:
- Create Custom
FragmentFactory - Create Custom
NavHostFragment - Asigne it to
FragmentContainerViewby usingandroid:name="com.package.CustomNavHostFragment"
But how I can do it by using this Navigation Advanced Sample ?
Because now on Activity recreate I'm getting typical HILT error at package.MainActivity.onCreate(MainActivity.kt:23)
EDIT:
More about the problem. By this provided simple we should use
NavigationExtension.kt and setup everything by using BottomNavigationView.setupWithNavController
And problem is that we need to use the default NavHostFragment in order to create a container for each navigation graph.
Is it possible somehow to use custom NavHostFragment? If yes, how can I overite that NavHostFragment.onCreate() mechanism?
I'm talking about this line in NavigationExtension.kt class
If I understood your problem correctly, you want to create a custom
NavHostFragment? Yes, that is possible but you don't need to overwriteNavHostFragment.onCreate(). Create a customNavHostFragmentwith the following steps: First, create aMainFragmentFactoryMainFragmentFactory
Then you need to attach your fragmentFractory to your custom
MainNavHostFragmentMainNavHostFragment
Now you need to add your custom
NavHostFragmentto youractivity_main.xmlActivity_main.xml
Dagger-Hilt will now create all your fragments and instantiate it.