> When the host activity undergoes a configurat...
# compose
m
When the host activity undergoes a configuration change, asynchronous work continues in the
ViewModel
, whether it is scoped to the activity or to specific composable. This is the key to persistence.
developer.android.com/topic/libraries/architecture/viewmodel
How can this be the case? Compositions aren’t persisted across configuration changes, are they? If a
ViewModel
is scoped to a composable, shouldn’t be it cleared on configuration change?
v
The implementation is built on top of
Activity::onRetainNonConfigurationInstance
. It may be possible to preserve coroutines using
retain
as well, since it's based on
ViewModel
.
I'd recommend handling all configuration changes (
android:configChanges="allKnown"
) to avoid worrying about activity recreation