Does the automatic saved state population of navig...
# compose
a
Does the automatic saved state population of navigation arguments only work with HiltViewModel or is it also populated when using Koin for instance? Or do I need to use hiltNavGraphViewModel? (as shown here:

https://youtu.be/0z_dwBGQQWQ?t=968

)
v
SavedStateViewModelFactory
 is the default factory used when using 
by viewModel()
You can use it without Hilt https://developer.android.com/jetpack/androidx/releases/navigation#2.2.0
a
Ah thanks! Exactly what I was looking for. It says "when using 
by navGraphViewModels()"
will try this out
v
That’s in the non-compose world I think. Compose uses by
viewModel()
But it should work the same way
a
Ah true, thanks for the info
mhm, does not really work
java.lang.ClassCastException: java.lang.Object cannot be cast to androidx.lifecycle.ViewModel at androidx.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:219) at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:278) at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:112)
when using by viewModel()
org.koin.core.error.InstanceCreationException: Could not create instance for [Factory:'app.project.chat.ui.screens.chat.ChatViewModel'] at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:61) at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:36) at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:103)
when using = get() in parameter
sooo the normal way does not work for me: java.lang.ClassCastException: java.lang.Object cannot be cast to androidx.lifecycle.ViewModel
getStateViewModel actually works but the id is not passed in
s
I'd have a problem with new viewmodel instance creatIon instead of return existing one when use Compose Navigation. Same with Hilt as with Koin.
a
what do you mean?
i
That stack trace indicates that you are using the default factory and not a factory that knows anything about Koin. Have you looked at the Koin docs? https://insert-koin.io/docs/reference/koin-android/compose/#viewmodel-for-composable