Marko Novakovic
04/05/2021, 7:20 AMremember {}
saves X for recomposition but when composable leaves the screen X is forgotten. if I want to save X even when composable leaves the screen I should use rememberSaveable {}
right? it seems weird because concept of rememberSaveable {}
is for surviving recreating
but composable leaving the screen is not recreation
. conceptually not the same. should I use rememberSaveable {}
or there is some other way to handle this use case?knthmn
04/05/2021, 7:33 AMMarko Novakovic
04/05/2021, 7:40 AMViewModel
or something and in that case you can make composables(items) in the list stateless (implementation differs from use case to use case) but what if you don’t need these items inside ViewModel
? maybe your use case is so simple and you would introduce ViewModel
just for saving checked state? this is all maybe and probably not good example but I hope you get a pointArkadii Ivanov
04/05/2021, 11:49 AMColton Idle
04/05/2021, 11:51 AMknthmn
04/05/2021, 1:49 PMAdam Powell
04/05/2021, 6:57 PMviewModel
composable is doing is hoisting your state into LocalViewModelStoreOwner.current
for youAdam Powell
04/05/2021, 6:59 PMMarko Novakovic
04/06/2021, 3:42 AMMarko Novakovic
04/06/2021, 3:43 AMAndrey Kulikov
04/07/2021, 2:11 PMrememberSaveable
can also be used inside LazyColumn
items for not loosing the local state when the item is scrolled off the screen(for example for checked state as you mentioned). so activity recreation is just one of the use cases of rememberSaveable
Marko Novakovic
04/07/2021, 2:36 PMMarko Novakovic
04/07/2021, 2:45 PMremember {}
and rememberSaveable {}
and scroll item off the screen, than bring it back to see what’s going on