Closed dima-ko closed 3 years ago
hi!
ViewModel
in moko-mvvm for android just subclass of ViewModel
from android architecture components. so all same as in AAC.
https://developer.android.com/topic/libraries/architecture/viewmodel
you should not call onCleared
manually - it will be called by android.
but in your code invalid usage of livedata. you should call ld()
function to transform common livedata into android livedata with observe(lifecycle, observer)
function.
viewModel.pageResultLD.ld().observe(this, Observer<Result<List<CountryRow>>> { result ->
// update UI
})
in this case you should not removeObserver manually, because it will be controlled by AAC livedata logic with lifecycle.
also you can use
viewModel.pageResultLD.bind(this) { result ->
// update UI
})
it call ld().observe
inside
Hey, guys. I want to use your MVVM approach but without MvvmActivity/MvvmFragment. Is it possible to just observe LiveData? Will it bring any memory leaks? Should I call
ViewModel.onCleared()
at some point? Here is the example code: