Hello Franky,
Well the beauty of Hilt is that it does that for you, you just have to add extras to your intent and after, inside ViewModel, if you query savedState for that extra Key it will be there. All remaining dependencies too.
Regarding CommonPreferencesHelper, how are you providing it, something like this?
@InstallIn(ApplicationComponent::class)
@Module
object AppProviders {
@Provides
@Singleton
fun provideCommonPreferencesHelper(...) = CommonPreferencesHelper(...)
}
To follow your viewModel creation, put a break point in:
ViewModelProvider(this).get(getViewModelClass())
And you will see this chain of calls:
ViewModelProvider.kt (get() line 170)> AbstractSavedStateViewModelFactory.kt (create() line 66) > HiltViewModelFactory.kt (create() line 62) > DaggerYour_HiltComponents_ApplicationC.kt (get()) > ActivityCImpl.this.getYourActivityViewModel_AssistedFactory()
which will contain you dependencies generated for you by Hilt, example:
private YourViewModel_AssistedFactory getYourViewModel_AssistedFactory() {
return YourViewModel_AssistedFactory_Factory.newInstance(DaggerYourApp_HiltComponents_ApplicationC.this.getCommonPreferencesHelper());
}}
Hope it helped!