https://kotlinlang.org logo
#compose
Title
# compose
r

robnik

02/27/2021, 8:06 PM
What is the difference between
rememberSavable
and
savedInstanceState
. Both are mentioned in https://developer.android.com/jetpack/compose/state. They look like they do the same thing.
d

Dominaezzz

02/27/2021, 8:12 PM
The latter was deprecated for the former in the most release.
👍 1
Similarly to how we previously removed 
state { 0 }
 composable and now promote usage like 
remember { mutableStateOf(0) }
 we are going to remove 
savedInstanceState { 0 }
 composable. You should use 
rememberSaveable { mutableStateOf(0) }
 instead and it will save and restore automatically if the type used inside the MutableState can be stored in the Bundle. If previously you were passing a custom saver object now you need to use a new overload of rememberSaveable which has 
stateSaver
 parameter. The usage will look like this: 
val holder = rememberSaveable(stateSaver = HolderSaver) { mutableStateOf(Holder(0)) }
👍 1
5 Views