I have a Room entity as so:
@Entity(tableName = "user")
public class User {
@PrimaryKey
@ColumnInfo(name = "id")
private int id;
@ColumnInfo(name = "name")
private String name;
@ColumnInfo(name = "age")
private int age;
public User() {}
public User(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
and ViewModel as so:
public class MainViewModel extends AndroidViewModel {
public MainViewModel(@NonNull @NotNull Application application) {
super(application);
}
public LiveData<List<User>> fetchLiveUsers() {
return repository.fetchUsers();
}
}
and observing the LiveData as so:
mainViewModel
.fetchLiveUsers()
.observe(getViewLifecycleOwner(), new Observer<List<User>>() {
@Override
public void onChanged(List<User> userList) {
if(userList != null)
usersAdapter.setModelsList(userList);
}
});
When I have a large dataset of users, such as 1000+ users, and I'm observing this live data, any changes in the database will trigger the onChanged() method.
Does this mean that each time onChanged() is called, the 1000+ users get loaded from the Room database, or does the updated user only get loaded from the database to update the current User list being observed by livedata?