Open
Description
What is the best approach?
// Only expose livedata
public class MyViewModel extends ViewModel {
private MutableLiveData<List<User>> users = new MutableLiveData();
public void loadUsers() {
// Do an asynchronous operation to fetch users.
users.postValue(/* ---- userList --- */);
}
}
// Expose livedata and instance variable userList
public class MyViewModel extends ViewModel {
private MutableLiveData<List<User>> users = new MutableLiveData();
private List<User> userList;
//Expose already fetched list
public List<User> getUserList() {
return userList;
}
public void loadUsers() {
// Do an asynchronous operation to fetch users.
this.userList = userList;
users.postValue(/* ---- userList --- */);
}
}
Metadata
Metadata
Assignees
Labels
No labels