How to update LiveData of a ViewModel from background service and Update UI

前端 未结 5 1331
梦毁少年i
梦毁少年i 2020-12-07 12:56

Recently I am exploring Android Architecture, that has been introduced recently by google. From the Documentation I have found this:

public class MyViewModel         


        
5条回答
  •  天命终不由人
    2020-12-07 13:28

    You can use MutableLiveData.postValue(T value) method from background thread.

    private void loadUsers() {
        // do async operation to fetch users and use postValue() method
       users.postValue(listOfData)
    }
    

提交回复
热议问题