Hlw everyone, rememberSaveable not working for me ...
# compose
a
Hlw everyone, rememberSaveable not working for me can someone help what can be the issue It's not restoring the value for me sharing code snippet and recording in 🧵
Copy code
@Composable
internal fun LoginScreen(navigator: AuthNavigator) {
    var num by rememberSaveable {
        mutableStateOf("hello")
    }

    Column(
        modifier = Modifier.fillMaxSize()
    ) {
        Button(
            onClick = {
                num += "1"
            },
            modifier = Modifier.size(100.dp)
        ) {
            Text(text = num)
        }
    }
}
I have set my background process limit to 0 to reproduce process death scenario
tried adding logs on saver
Copy code
var num by rememberSaveable(
        saver = object : Saver<MutableState<String>, String> {
            override fun restore(value: String): MutableState<String>? {
                println("restoring $value")
                return mutableStateOf(value)
            }

            override fun SaverScope.save(value: MutableState<String>): String? {
                println("saving ${value.value}")
                return value.value
            }

        }
    ) {
        mutableStateOf("hello")
    }
I am not getting callback on
restore
method, when opening app after process death
save
is being called as expected
Screen Recording 2024-03-07 at 9.37.29 AM.mov
v
What is
AuthNavigator
? I tried this code in new simple project (Empty Compose Activity in Android Studio) and it's working 🤔
🫥 1
a
oh ignore AuthNavigator
not sure what can be the issue then , I tried saveStateHandle (with KOIN) but it also didn't work 🧐 something wrong with my project 🤔
This is sorted, Issue with my code, For some reason screen was re-launched and everything was created new Thanks for the help!