Arslan Mushtaq
11/26/2019, 8:03 PMvoben
11/26/2019, 8:13 PMviewModelScope
and call launch viewModelScope.launch {}
. Inside your launch block, you can call your suspending function which retrieves the integer from your repo and resumes once it gets the value. Then in your viewmodel, you can use livedata to notify the fragment of changes
fun doSomething() {
viewModelScope.launch {
val myInteger = repository.getMyInteger()
myLiveData.value = myInteger
}
}
Arslan Mushtaq
11/26/2019, 8:22 PMvoben
11/26/2019, 8:32 PMHome
fragment and view added items in the cart fragment when you click the cart icon. In that case you could use a viewmodel scoped to the activity which contains both fragments to communicate from the home fragment to the activity’s cart icon badge count