title: MutableLiveData not updating in UI
body: <p><strong>UPDATE:</strong>
  If i move to another fragment and return to this one the TextView gets updated...</p>
  
  <p>I am unable to get the MutableLiveData in the UI to update to a new value either by using setValue() or postValue(). I can get this to work by changing the MutableLiveData to ObservableData but the point is to use LiveData not ObservableData.</p>
  
  <p>I have similar things working in other views without an issue. Unsure whats happening here... The only thing I can think of is that I am jumping back and forth between a camera activity (via intent) and this fragment. On the activity result I am setting data from the fragment to the ViewModel.</p>
  
  <p>I dont believe that I need to set any observer for the value in the fragment since i have 2 way databinding between the XML and ViewModel.</p>
  
  <p>my_fragment.XML</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="myViewModel"
              type="com.example.myapplication.MyViewModel" /&gt;
      &lt;/data&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
              &lt;TextView
              android:id="@+id/textView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@={myViewModel.photosCount}"
              tools:text="1" /&gt;
  
             &lt;Button
                 android:id="@+id/btnTakePhoto"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Take Picture"
                 android:onClick="@{myViewModel::navClicked}"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/layout&gt;
  </code></pre>
  
  <p>MyViewModel.java</p>
  
  <pre><code>private MutableLiveData&lt;String&gt; photosCount = new MutableLiveData&lt;&gt;();
  private MutableLiveData&lt;Boolean&gt; takePhoto = new MutableLiveData&lt;&gt;();
  
  public MyViewModel() {
      photosCount.setValue("0"); // This correctly sets the value to "0" in UI
      takePhoto.setValue(true);
  }
  
  public MutableLiveData&lt;String&gt; getPhotosCount() {
      return photosCount;
  }
  
  public MutableLiveData&lt;Boolean&gt; getTakePhoto() {
      return takePhoto;
  }
  
  public void storeImage() {
      ....
      Log.d(TAG, "Updating UI count to: " + String.valueOf(count)); // this shows the correct value that should be updated in the UI
      photosCount.setValue(String.valueOf(count));
      Log.d(TAG, "Updated value: " + photosCount.getValue()); // this shows the correct updated value
      ...
  }
  
  public void navClicked(@NonNull View view) {
      if (view.getId() == R.id.btnTakePhoto) {
          takePhoto.setValue(true);
      }
  }
  
  </code></pre>
  
  <p>Now, since LiveData does not guarantee updating the UI at the time of changing the value I thought this might be a binding dispatch issue. That hasent resolved the issue either...</p>
  
  <p>MyFragment.java</p>
  
  <pre><code>private MyViewModel myViewModel;
  MyFragmentBinding binding;
  
  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      super.onCreateView(inflater, container, savedInstanceState);
  
      myViewModel = new ViewModelProvider(this).get(MyViewModel.class);
  
      binding = DataBindingUtil.inflate(inflater, R.layout.my_fragment, container, false);
      binding.setMyViewModel(myViewModel);
  
      return binding.getRoot();
  }
  
  @Override
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
      viewModel.getTakePhoto().observe(getViewLifecycleOwner(), takePhoto -&gt; {
          if (takePhoto) {
              Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
              if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                  File photo = viewModel.createImageFile();
                  if (photo != null) {
                      Uri photoURI = FileProvider.getUriForFile(getActivity(),"com.example.fileprovider", photo);
                      intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                      this.startActivityForResult(intent, Constants.RequestCodes.MY_REQUEST_IMAGE_CAPTURE);
                  }
              }
          }
      });
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == Activity.RESULT_OK) {
          if (requestCode == Constants.RequestCodes.MY_REQUEST_IMAGE_CAPTURE) {
              viewModel.storeImage();
          }
      }
  }
  </code></pre>
  
  <p>Again, If you switch photosCount from MutableLiveData to ObservableData the problem is fixed however this is not LiveData.</p>