title: How can I get a value from LiveData?
body: <p>I am using Room for the first time. I am having a look at the LiveData concept. I know that we can fetch records from DB into LiveData and haveObservers attached.</p>
  
  <pre><code>@Query("SELECT * FROM users")
  
  &lt;LiveData&lt;List&lt;TCUser&gt;&gt; getAll();
  </code></pre>
  
  <p>But I am performing sync in the background, where I need to fetch data from server and compare it with the data in RoomDatabase table called "users" and then either insert,update or delete from users table. How can I traverse the LiveData list before taking any action ? As it gives error if I put it in for loop.</p>
  
  <p>OR should I not use LiveData for this scenario ?</p>
  
  <p>I guess I need to call </p>
  
  <pre><code>&lt;LiveData&lt;List&lt;TCUser&gt;&gt; getAll().getValue()
  </code></pre>
  
  <p>But is it the right thing to do ? Here is some more code to give idea as to what I am trying to do:</p>
  
  <pre><code>List&lt;User&gt;serverUsers: Is the data received from a response from an API
  
  private void updateUsers(List&lt;User&gt; serverUsers) {
      List&lt;UserWithShifts&gt; users = appDatabase.userDao().getAllUsers();
      HashMap&lt;String, User&gt; ids = new HashMap();
      HashMap&lt;String, User&gt; newIds = new HashMap();
  
      if (users != null) {
          for (UserWithShifts localUser : users) {
              ids.put(localUser.user.getId(), localUser.user);
          }
      }
  
      for (User serverUser : serverUsers) {
          newIds.put(serverUser.getId(), serverUser);
  
          if (!ids.containsKey(serverUser.getId())) {
              saveShiftForUser(serverUser);
          } else {
              User existingUser = ids.get(serverUser.getId());
              //If server data is newer than local
              if (DateTimeUtils.isLaterThan(serverUser.getUpdatedAt(), existingUser.getUpdatedAt())) {
                  deleteEventsAndShifts(serverUser.getId());
                  saveShiftForUser(serverUser);
              }
          }
      }
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>@Query("SELECT * FROM users")
  List&lt;UserWithShifts&gt; getAllUsers();
  </code></pre>
  
  <p>Is the first line in updateUsers() the right way to fetch data from DB to process before inserting new ones or should it be instead</p>
  
  <pre><code>&lt;LiveData&lt;List&lt;User&gt;&gt; getAll().getValue()
  </code></pre>
  
  <p>Thanks,</p>