6

So, I have ViewModel that looks like this

class MyViewModel<E, S> : ViewModel() {

    private val _state = MutableLiveData<S>()
    val state: LiveData<S>
        get() = _state

    abstract fun onEventReceived(event: E)

    protected fun pushState(state: S) {
        _state.value = state
    }
}

And as usual I have observer code in my Activity/ Fragment

viewModel.state.observe(this, Observer {
    // Do something here
})

My problem is when I try to emit values like this

pushState(State.A)
pushState(State.B)
pushState(State.C)

In my Activity/Fragment, it only received C.

Anyone has experience with this kind of behaviour? Please kindly share your workaround.

Khairil Ushan
  • 2,358
  • 5
  • 26
  • 29

0 Answers0