Search code examples
javaandroidgpslocationandroid-pendingintent

FusedLocationClient interval Slowing down while phone is locked


So I've been working with FusedLocationClient now for about 2 months. The client is passed a location request which correctly sets the interval at which to retrieve location updates, at least while the phone is 'awake'. If I set the interval to 1 min, I will get updates almost exactly every min, but when the phone is locked and then I come back to the app I can see that updates only occurred once every 10 minuets.

Anyone with experience using the FusedLocationClient for Android have any clues as to why this may be happening? The Client is looping with Looper.myLooper(), does this thread slow down if the phone is locked?

  mLocationRequest = new LocationRequest();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(OneMin);
    mLocationRequest.setFastestInterval(OneMin);
    mLocationRequest.setMaxWaitTime(OneMin);

Update to the original question******** So after switching Fused Location Client to the Pending Intent Method from the callback method I am still getting the same result. This pending intent method is supposed to run the client from the app background as opposed to the foreground, yet Location updates still slow down to 10 mins. Here is my log from my pending intent.

06-28 07:55:39.201 D/ddd: onHandleIntent: 38.5377347, -106.9408941
06-28 07:56:41.128 D/ddd: onHandleIntent: 38.5377747, -106.9406465
06-28 07:57:43.055 D/ddd: onHandleIntent: 38.5372963, -106.9409439
06-28 07:59:33.098 D/ddd: onHandleIntent: 38.5378022, -106.9406814
06-28 08:10:22.646 D/ddd: onHandleIntent: 38.5378164, -106.9410321
06-28 08:20:35.668 D/ddd: onHandleIntent: 38.5378373, -106.9408016
06-28 08:30:35.790 D/ddd: onHandleIntent: 38.5377677, -106.9407083

You can see from the time stamp that the interval goes from 1 min to 10. Any ideas on how to prevent this? Android docs are leading deep into rabbit holes suggesting to use Scheduled job, but no straight forward examples are given.


Solution

  • If you are testing this on Android 8.0 (API level 26) or higher, it will only retrieve updates a few times each hour. This is from the Android Documentation.

    In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.

    Devices running API level 25 and lower will receive background updates normally. More information can be found at Android Versions Overview.