问题
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?
来源:https://stackoverflow.com/questions/62139420/android-savedstatehandle-doesnt-save-in-viewmodel