Closed valeriyo closed 3 years ago
"Don't keep activities" is a lifecycle scenario that only happens when "don't keep activities" is enabled. BackstackHost is a retained fragment, so it has the same lifecycle as an Activity, but it is kept alive across configuration changes.
It appears that with "don't keep activities", all activities are immediately finish()
ed when they are not in front, so that would mean that any other solution for surviving configuration changes, even Jetpack ViewModel's ViewModelStore, should be similarly terminated as you navigate between Activities if "don't keep activities" is enabled.
That would mean that only statics would survive, but statics aren't safe as they are shared between tasks.
By standard Android behavior, finish()
for Activity only happens when super.onBackPressed()
happens.
Yeah, makes sense:
BackstackHost
are re-created, which is similar to a process restart for the UI scoped objectsBackstackHost
remains intact.
Thanks, @Zhuinden I believe this is effectively answered, but "don't keep activities" is very interesting nonetheless
I have turned on the "Don't keep activities" toggle in developer options to test state persistence.
As soon as I switch away from my app, the
BackstackHost.onDestroy
is called, which wipes out all scoped service instances as well. Is this how it's supposed to work?I thought the scoped services should survive activity going away. But if
BackstackHost
has same lifecycle as the activities - then, what's the point of it?