When using the NavHost and NavController, what is ...
# compose
r
When using the NavHost and NavController, what is the point of restricting yourself to passing ints and strings and other serializable args, when you can have a big ViewModel object with any kind of object in it, and pass that around by reference?
i
What happens when your process dies and recreated? (try it with 'Don't keep activities' on)
Spoiler: your ViewModel and 'any kind of object in it' gets destroyed
But the whole point of Android is that users don't lose their state when the process dies and is recreated from saved state, so you're back on the same destination you're left at. You need a source of truth that is going to still be there after that happens to ensure that the destination comes back into the same state as it was in. That means you already need a repository or some other source of truth, so passing around just an ID of what item to load from that repository is exactly the pattern you should be using
👍 1
r
Thanks, I see. I didn't know about that setting.
i
Even on high end phones, opening the Camera app is often enough to kick ~every other app out of memory, so this is a very real world scenario. The developer option just helps with testing it consistently