In the Guide to app architecture by Google there is an example, which I do not understand -
UserProfileViewModel:
public class UserProfileViewModel extends ViewModel {
private LiveData<User> user;
public LiveData<User> getUser() {
return user;
}
}
UserProfileFragment:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
viewModel.getUser().observe(this, user -> {
// Update UI.
});
}
When I look at the LiveData reference, there is only the following observe
method:
observe(LifecycleOwner owner, Observer<T> observer)
I am confused, that the method signature does not match:
The LifecycleOwner
is the support library Fragment
, all right.
But how can the expression user-> { some code }
be an Observer object?