MutableLivedata观察者触发

问题描述 投票:0回答:2

我对MutableLiveDataViewmodel有疑问。 Qazxswpoi的setValue功能是否触发观察?如果我们用MutableLiveData改变MutableLiveData的内容,可能会被触发吗?

android mvvm viewmodel mutablelivedata
2个回答
1
投票

我对此表示怀疑。只有以下方法将事件分派给observables:

setValue

liveData.postValue("a"); liveData.setValue("b");


0
投票

https://developer.android.com/reference/android/arch/lifecycle/MutableLiveDatasetValue()都会引发这些事件。唯一的区别是,postValue也可以从后台线程触发观察事件。然而,必须在主线程中调用postValue()setValuepostValue()更受欢迎。

© www.soinside.com 2019 - 2024. All rights reserved.