Guilherme Delgado
1 min readJun 30, 2020

--

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!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Guilherme Delgado
Guilherme Delgado

Written by Guilherme Delgado

Software Engineer at BlissApplications 🇵🇹 • github.com/GuilhE • When I’m not coding I’m 🧗🏽or 🏄‍♂️

Responses (1)

Write a response