title: Request fresh value from LiveData
body: <p>I try to get user (gps) location and use that in parameter of api request.</p>
  
  <p>I have implemented <code>LocationLiveData</code>, which is also used in other places of the app when I need user location. </p>
  
  <p>The api request is done inside the <code>housesRepository</code>.</p>
  
  <p>My current problem is that when I call view model <code>loadHousesNearby()</code> second this, LocationLiveData returns cached location data. It is not fetching fresh location from FusedLocationProviderClient.</p>
  
  <p>How should I force <code>LocationLiveData</code> to get completely new location and not return the cached one?</p>
  
  <p><strong>LocationLiveData</strong></p>
  
  <pre><code>public class LocationLiveData extends LiveData&lt;Location&gt; {
      private final Context context;
      private FusedLocationProviderClient fusedLocationProviderClient;
  
      public LocationLiveData(Context context) {
          this.context = context;
      }
  
      @Override
      protected void onActive() {
          super.onActive();
          FusedLocationProviderClient locationProviderClient = getFusedLocationProviderClient();
          LocationRequest locationRequest = LocationRequest.create();
          locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
          Looper looper = Looper.myLooper();
          locationProviderClient.requestLocationUpdates(locationRequest, locationCallback, looper);
      }
  
      private FusedLocationProviderClient getFusedLocationProviderClient() {
          if (fusedLocationProviderClient == null) {
              fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
          }
          return fusedLocationProviderClient;
      }
  
      @Override
      protected void onInactive() {
          if (fusedLocationProviderClient != null) {
              fusedLocationProviderClient.removeLocationUpdates(locationCallback);
          }
      }
  
      private LocationCallback locationCallback = new LocationCallback() {
          @Override
          public void onLocationResult(LocationResult locationResult) {
              setValue(locationResult.getLastLocation());
          }
      };
  }
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>public class MyModel extends ViewModel {  
  
      private final LocationLiveData locationLiveData;
      private final MediatorLiveData&lt;House&gt; houses;
  
      ...
  
      public void loadHousesNearby() {
        houses.addSource(locationLiveData, location -&gt; {
                      houses.removeSource(locationLiveData);
                      houses.addSource(
                              housesRepository.getHousesNearby(new LatLng(location.getLatitude(), location.getLongitude())),
                              housesResp -&gt; {
                                  houses.setValue(housesResp);
                              }
                      );
                  }
          );
  
      }
  }
  </code></pre>