I have a ViewModel which takes a SavedStateHandle
parameter. I am saving a String in there like this:
private fun saveString(str: String) {
state.set(KEY_STRING, str)
}
Then I force-close my app and relaunch it, and want to retrieve the saved string like this:
fun getSavedString(): String? {
return state.get<String>(KEY_String)
}
However, it always returns null. Any ideas how to use SavedStateHandle correctly?
adb
.SavedStateHandle
save the state for this scenario?SavedStateHandle
. Android doc clearly states: These values will persist after the process is killed by the system and remain available via the same object.Bundle
orSavedStateHandle
) is for when the system terminates the process due to low memory conditions, but the user returns to the app quickly (<30 minutes, last I checked).