How to clear LiveData stored value?

后端 未结 7 1176
暖寄归人
暖寄归人 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:51

    Might be an ugly hack but... Note: it requires RxJava

    menuRepository
                .getMenuTypeAndMenuEntity(menuId)
                .flatMap { Single.fromCallable { menuTypeAndId.postValue(Pair(it.first, menuId)) } }
                .flatMap { Single.timer(200, TimeUnit.MILLISECONDS) }
                .subscribe(
                    { menuTypeAndId.postValue(null) },
                    { Log.d(MenuViewModel.TAG, "onError: ${it.printStackTrace()}") }
                )
    

提交回复
热议问题