Location fetched from cache (older location) if the app is resumed from background

45 views Asked by At

I am using the following function to get user location:

private void getCurrentLocation() {
        try {
            final Task<Location> task = client.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null);
            task.addOnSuccessListener(this);
            task.addOnFailureListener(this);
        } catch (Exception e) {
            e.printStackTrace();
            Analytics.logException(e);
            broadCastLocation(ACTION_LOCATION_FAILED, null);
        }
}

where client is client = LocationServices.getFusedLocationProviderClient(this);

Scenario one (In this scenario the user is able to reproduce the issue)

  1. The first location of the day is fetched correctly. After that user press the home button and does not clear the app from background
  2. User travels to a good 30-40 kms from the previous location and checks in again. Here the previous location is fetched instead of the current location. NOTEL: I am NOT using getLastLocation function to get the location. I am calling getCurrentLocation everytime i fetch the location of the user.

Scenario two (This scenario works perfectly fine)

  1. The first location of the day is fetched correctly. After that user kills the application from the background
  2. User travels to a good 30-40 kms from the previous location and checks in again. Here the correct current location is fetched.

Note: The location fetching code is written in a JobIntent service extended class

public class LocationService extends JobIntentService

And the Receiver is extending a BroadcastReceiver

public class LocationReceiver extends BroadcastReceiver {

The location service is ON. The user has given location permission.

0

There are 0 answers