Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connecting The Dots :: Pure SavedState - ViewModel body
class SomeViewModel(/* ..ommited.. */){
val counter = MutableLiveData<Int>(0)
init {
counter.value = savedStateHandle.get("counter") ?: 0
counter.observeForever { newValue ->
savedStateHandle.set("counter", newValue)
}
}
fun onPlusClick() {
counter.value = (counter.value ?: 0) + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.