title: Observable DataBinding ObservableInt vs. LiveData with different results On Confguration change
body: <p>I am testing the behavior of <code>DataBinding</code> observable when it comes to use a <code>LiveData</code> vs. <code>ObservableInt</code>.</p>
  
  <p>I have simple layout with a button that triggers a counter for both <code>LiveData</code> &amp; <code>ObservableInt</code> variables that I store in the <code>ViewModel</code>, I update their values using <code>BindingAdapter</code></p>
  
  <p>Both  <code>LiveData</code> &amp; <code>ObservableInt</code> variables count up normally; but when there is a device configuration change (screen rotation for my test), the <code>ObservableInt</code> countinues count up with button hits, although the <code>LiveData</code> dismisses one or two counts.</p>
  
  <p>Below gif will illustrate more</p>
  
  <p><img src="https://media.giphy.com/media/ZbYmVHgpFENWHdZEum/giphy.gif" alt=""></p>
  
  <p>My question is how to solve this problem? 
  I mainly need a <code>LiveData</code> for further <code>Transformations</code></p>
  
  <p><strong>Layout</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"&gt;
  
      &lt;data&gt;
  
          &lt;variable
              name="viewmodel"
              type="com.example.android.databindingobservableintlivedata.MyViewModel" /&gt;
  
      &lt;/data&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center"
          android:orientation="vertical"
          tools:context=".MainActivity"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center"&gt;
  
              &lt;TextView
                  android:id="@+id/observableint_label"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="ObservableInt: " /&gt;
  
              &lt;TextView
                  android:id="@+id/observableint_count"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="0"
                  app:textValueForObservableInt="@{viewmodel.countObservableInt}" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="8dp"
              android:gravity="center"&gt;
  
              &lt;TextView
                  android:id="@+id/livedata_label"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="LiveData: " /&gt;
  
              &lt;TextView
                  android:id="@+id/livedata_count"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="0"
                  app:textValueForLiveData="@{viewmodel.countLiveData}" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;Button
              android:id="@+id/btn_count"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:layout_marginTop="16dp"
              android:onClick="@{() -&gt; viewmodel.onCount()}"
              android:text="Count" /&gt;
  
  
      &lt;/LinearLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p><strong>Activity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          ActivityMainBinding mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
          MyViewModel viewModel = ViewModelProviders.of(this).get(MyViewModel.class);
  
          mBinding.setViewmodel(viewModel);
          mBinding.setLifecycleOwner(this); 
  
      }
  }
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>public class MyViewModel extends ViewModel {
  
      public MutableLiveData&lt;Integer&gt; countLiveData = new MutableLiveData&lt;&gt;(0);
      public ObservableInt countObservableInt = new ObservableInt(0);
  
      public void onCount() {
          countObservableInt.set(countObservableInt.get() + 1);
          int value = countLiveData.getValue() == null ? 0 : countLiveData.getValue();
          countLiveData.postValue(value + 1);
      }
  
  }
  </code></pre>
  
  <p><strong>BindingAdapters</strong></p>
  
  <pre><code>public class BindingAdapters {
  
      @BindingAdapter("textValueForObservableInt")
      public static void bindObservableIntInText(TextView text, ObservableInt value) {
          text.setText(String.valueOf(value.get()));
      }
  
      @BindingAdapter("textValueForLiveData")
      public static void bindLiveDataIntegerInText(TextView text, MutableLiveData&lt;Integer&gt; value) {
          text.setText(String.valueOf(value.getValue()));
      }
  
  }
  </code></pre>