title: How to keep user inputs on screen orientation change with Android DataBinding library?
body: <p>I'm at the very beginning of a new Android project. After playing around with MVP in my last project, I want to implement MVVM with Data Binding this time.</p>
  
  <p>I have a problem understanding DataBinding correctly when it comes to configuration changes like screen orientation change. </p>
  
  <p>All DataBinding samples out there (all I have found when looking for "android mvvm databinding") have the same problem: <strong>When I enter something in an EditText and rotate the screen, the EditText is empty afterwards.</strong></p>
  
  <p>As soon as I have something like the following in my layout, I can't get the views (EditText in this case) to restore their state after screen rotation change. </p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;data&gt;
          &lt;variable
              name="vm"
              type="com.example.app.TestViewModel" /&gt;
      &lt;/data&gt;
  
      &lt;EditText android:id="@+id/question"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="@={vm.question}" 
          android:hint="Question" /&gt;
  
  &lt;/layout&gt;
  </code></pre>
  
  <p>I guess this is because of assigning a new view model instance in the activities onCreate method every time.</p>
  
  <pre><code>@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      ActivityTestBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_test);
      binding.setVm(new TestViewModel());
  }
  </code></pre>
  
  <p><strong>How do you handle that correctly?</strong></p>
  
  <p>I can't develop an app with several forms that forget all user inputs at screen orientation.</p>