How to clear LiveData stored value?

后端 未结 7 1178
暖寄归人
暖寄归人 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 02:57

    In my case SingleLiveEvent doesn't help. I use this code:

    private MutableLiveData someLiveData;
    private final Observer someObserver = new Observer() {
        @Override
        public void onChanged(@Nullable Boolean aBoolean) {
            if (aBoolean != null) {
                // doing work
                ...
    
                // reset LiveData value  
                someLiveData.postValue(null);
            }
        }
    };
    

提交回复
热议问题