Hi :wave:. Let's say I've have a complex object I want to persist even if the screen is rotated as s...
l
Hi 👋. Let's say I've have a complex object I want to persist even if the screen is rotated as state: should I use
ViewModel
or
remeberSaveable
? Which is best practice ?
a
Are you just talking about config change? You can override all config change so your activity does not get recreated, so the state is retained
l
In fact, I would like the user to be able to rotate the phone, and have a part of the @Composable updated, but not its state.
a
Yeah, Compose will react automatically when config changes without losing state, if you do above
l
Thank you : I'll try it right now 😃
I've just found on Android Documentation (https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange) that using
configChanges
should be used as a last resort. And that
ViewModels
can be adapted for large data. So I think I'll use ViewModels, as my issue was due to the fact that I relied on the
Bundle
providen by
rememberSaveable
with too much data 😃
c
Sounds like your complex object should just be persisted to a db, or to a file (remember... you have to worry about process death too) and then you save the state of the id of that complex object. Also, what you read about configChanges is the "old" guidance. I'm sure the official guidance will be updated at some point to include saying that you should override configChanges in a pure compose app.