I f I wanted to save the state of my state class s...
# compose
n
I f I wanted to save the state of my state class so that I have it intact when I navigate back to that page, what would be my best bet: Datastore, Saver function, some other way? 🧵
Copy code
class MainPieceComposableState(
    enabled: Boolean,
    visible: Boolean,
    tileColor: Color,
) {
    var enabled by mutableStateOf(enabled)
    var visible by mutableStateOf(visible)
    var tileColor by mutableStateOf(tileColor)
}
What I mean is that I want to remember exactly in my Composable which Piece was visible/enabled etc and which wasn't.
I could also use a Room database but that might be overkill?
а
As i think, the Datastore preferences should be enough for this case
n
Thanks, will give it a try! 🙂
а
By the way, are you using one NavHost or multiple navhost, i've an issue with handling navigateUp event with multiple ones
n
Just NavHost, I followed a very basic tutorial...
а
Thank you at all, maybe other colleagues have implemented such case as I
👍 1
a
For choosing between
DataStore
(or another on-disk persistence) versus
Saver
+
rememberSaveable
, what behavior do you want if the app is completely closed, and relaunched in a fresh state?
😊 1
n
Yes, I need the state to be remembered if someone leaves the game for a few days and comes back to it.
so datastore makes more sense
👍 1
a
Agreed!
Saver
+
rememberSaveable
are equivalent to
savedInstanceState
, so if you want to persist state beyond an
Activity
being completed, you’ll need some sort of disk storage like
DataStore
🙌 2