title: LiveData onChanged not being called when data changes
body: <p>I am new to using <code>LiveData</code> and <code>ViewModels</code> and I don't fully understand how the data is updated.  </p>
  
  <p>According to the <a href="https://developer.android.com/topic/libraries/architecture/livedata" rel="nofollow noreferrer">Android Dev site</a>:  </p>
  
  <blockquote>
    <p>Instead of updating the UI every time the app data changes, your
    observer can update the UI every time there's a change.</p>
  </blockquote>
  
  <p>That sentence doesn't make sense to me.  I'm using a Sqlite database (without Room) and I'm asynchronously getting the data in the <code>getItems()</code> method of the <code>ViewModel</code>.  Does that mean when data is added or updated in the database, the <code>LiveData</code> will automatically detect it and <code>onChange</code> is called?</p>
  
  <p>According to the Android dev site, it says to begin observing a <code>LiveData</code> object in <code>onCreate</code>.  Before using <code>LiveData</code>, I was refreshing the data in <code>onResume</code> by querying the database then calling <code>notifyDataSetChanged()</code>.</p>
  
  <p>This code I have now displays the data when the <code>Fragment</code> loads, but if I delete or add new data to the database, the UI does not reflect the change.  I just think I don't have a basic understanding of how <code>LiveData</code> works and I can't find a good explanation anywhere.</p>
  
  <p>Help me StackOverflow, you're my only hope.</p>
  
  <pre><code>public class MyViewModel extends AndroidViewModel {
      private MutableLiveData&lt;List&lt;String&gt;&gt; items;
      private Application application;
  
      public MyViewModel(@NonNull Application application) {
          super(application);
          this.application = application;
      }
  
      public MutableLiveData&lt;List&lt;String&gt;&gt; getItems() {
          if (items == null) {
              items = new MutableLiveData&lt;&gt;();
              getItems();
          }
          return items;
      }
  
      private void getItems() {
          List&lt;String&gt; items = GetItems(); //async process
  
          this.items.setValue(items)
      }
  }
  
  public class ListFragment extends Fragment {
  
      @Override
      public void onCreate(final Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          MyViewModel model = ViewModelProviders.of(getActivity()).get(MyViewModel.class);
  
          final Observer&lt;List&lt;String&gt;&gt; observer = new Observer&lt;List&lt;String&gt;&gt;() {
              @Override
              public void onChanged(List&lt;String&gt; items) {
                  //update UI
              }
          };
  
          model.getItems().observe(this, observer);
      }
  
  }
  </code></pre>