We've made the full migration to nav3 and have not...
# compose
c
We've made the full migration to nav3 and have noticed that rememberSaveable values persist even when you should have a new instance of a screen on the stack. For example: User navigates screens
A -> B -> C -> A
. Where the 2nd
A
is a new instance. In this case the rememberSaveable value persists. We found out that's because it's not a new instance of
A
on the stack. The key we added to the stack did not change any parameters so when the NavEntry compares them using the classes'
toString()
method they are equal. We can easily override that method or add a random UUID parameter to the screens we want to have new instances but that feels hacky. I was wondering if there is something I'm missing in nav3 that will treat every key entry as unique regardless if that classes's parameters have changed or not.
Another way to do this is is to provide a clazzContentKey in the entry function like this:
Copy code
entry<NewsKey.News>(clazzContentKey = { UUID.randomUUID().toString() }
i
contentKey
is the unique key for all state so entries in the back stack that share the same
contentKey
will indeed have the same state. Adding a UUID is a good way of making sure each instance is unique
thank you frog 1