我对MutableLiveData
的Viewmodel
有疑问。 Qazxswpoi的setValue
功能是否触发观察?如果我们用MutableLiveData
改变MutableLiveData
的内容,可能会被触发吗?
我对此表示怀疑。只有以下方法将事件分派给observables:
setValue
liveData.postValue("a");
liveData.setValue("b");
https://developer.android.com/reference/android/arch/lifecycle/MutableLiveData和setValue()
都会引发这些事件。唯一的区别是,postValue
也可以从后台线程触发观察事件。然而,必须在主线程中调用postValue()
。 setValue
比postValue()
更受欢迎。