title: ViewModel and Data Binding
body: <p>Android has recently introduced <a href="https://developer.android.com/topic/libraries/architecture/index.html" rel="noreferrer">Architecture Components</a> and in particular a <a href="https://developer.android.com/topic/libraries/architecture/viewmodel.html" rel="noreferrer">ViewModel</a>, which is</p>
  
  <blockquote>
    <p>designed to store and manage UI-related data so that the data survives configuration changes such as screen rotations</p>
  </blockquote>
  
  <p>In example provided by Google, ViewModel is used like this:</p>
  
  <pre><code>public class MyActivity extends AppCompatActivity {
      public void onCreate(Bundle savedInstanceState) {
          MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class);
          model.getUsers().observe(this, users -&gt; {
              // update UI
          });
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Question:</strong> How does ViewModel suppose to correlate with the <a href="https://developer.android.com/topic/libraries/data-binding/index.html#custom_setters" rel="noreferrer">Data Binding</a>?</p>
  
  <p>I mean, in case of data binding there is going to be a <code>binding</code> which provides data for the UI.</p>
  
  <p>Is it going to look like this:</p>
  
  <pre><code>...
  model.getUsers().observe(this, users -&gt; {
    // update binding, that will auto-update the UI?
  });
  ...
  </code></pre>