In our app we used the Fused Location Provider (FLP) to track location. We've noticed that occasionally the app can get into a state where the location callback stops getting called. The app in question is used primarily on two tablets (a nexus 7 and LG G-pad 8.3). We have seen the issue occur on both devices. In general resetting the device seems to alleviate the issue. We believe we follow most of the best practices for using the FLP. But just in case we put together this sample code which illustrates how we use the FLP.
Get a google api client and call connect:
m_googleApiClient = builder
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
m_googleApiClient.connect()
Once connected we start listening for location callbacks:
@Override
public void onConnected(Bundle bundle) {
m_fusedLocationProviderApi.requestLocationUpdates(m_googleApiClient, m_locationRequest, this);
}
The location request looks like this:
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
We then implement the callback like so:
@Override
public void onLocationChanged(Location location) {
// set location member var and record timestamp.
}
When the issues occurs we don't appear to get any error callbacks. We've tried also calling reset() on the google api client when we detect we haven't received a GPS in a long time. We also monitor location availability using a timer every 2 seconds (using getLocationAvailability). Typically we find that having the user reset their device (power on, power off) fixes the issue.
Our questions are:
- Has anyone else noticed this issue with FLP?
- Is there more we can do to fix the issue short of having the user reset? Would remove adding location updates help?
- Is there more information we can/should collect to diagnose the issue?