Is there any behavioural difference between `ViewM...
# dagger
c
Is there any behavioural difference between
ViewModelComponent
and
ActivityRetainedComponent
? I’m an idiot and took too long to realize that
ActivityComponent
is not a descendant of
ViewModelComponent
. So I’m wondering what is the advantage of
ViewModelComponent
vs
ActivityRetainedComponent
. Thanks!
1
f
Activity retained component scopes the view model to the Lifecycle of the activity, whilst the dependencies in the viewmodelcomponent live as long as the view model is alive a.k.a viewmodel's lifecycle
c
Isn’t that the same thing? VM survives configuration changes, just like ActivityRetainedComponent https://developer.android.com/topic/libraries/architecture/viewmodel#lifecycle
a
ViewModelComponent
lives under
ActivityRetainedComponent
, and it has the same lifecycle as of a `ViewModel`that is annotated with
@HiltViewModel
. The most obvious difference is that ViewModelComponent holds an instance to a
SavedStateHandle
that belongs to a Fragment or an Activity. While
ActivityRetainComponent
has nothing to do with the
SavedStateHandle
of its Activity.
c
Ah ok! Thanks for responding! I didn’t realize that
👍 1