How to clear LiveData stored value?

后端 未结 7 1177
暖寄归人
暖寄归人 2021-01-30 02:34

According to LiveData documentation:

The LiveData class provides the following advantages:

...

Always up to date data: If a Li

7条回答
  •  借酒劲吻你
    2021-01-30 03:02

    The best solution I found is live event library which works perfectly if you have multiple observers:

    class LiveEventViewModel : ViewModel() {
        private val clickedState = LiveEvent()
        val state: LiveData = clickedState
    
        fun clicked() {
            clickedState.value = ...
        }
    }
    

提交回复
热议问题