Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class NameActivity extends AppCompatActivity {
private NameViewModel mModel;
protected void onCreate(Bundle savedInstanceState) {
// Get the ViewModel.
mModel = ViewModelProviders.of(this).get(NameViewModel.class);
// Create the observer which updates the UI.
final Observer<String> nameObserver = new Observer<String>() {
public void onChanged(@Nullable final String newName) {
// Update the UI, in this case, a TextView.
// Observe the LiveData, passing in this activity as the LifecycleOwner and the observer.
mModel.getCurrentName().observe(this, nameObserver);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment