Difference of setValue() & postValue() in MutableLiveData

后端 未结 7 1670
故里飘歌
故里飘歌 2020-11-28 05:34

There are two ways that make change value of MutableLiveData. But what is difference between setValue() & postVa

7条回答
  •  爱一瞬间的悲伤
    2020-11-28 06:23

    All above answers are correct. But one more important difference. If you call postValue() on field that has no observers and after that you call getValue(), you don't receive the value that you set in postValue(). So be careful if you work in background threads without observers.

提交回复
热议问题