0

I have an endless foreground service that request locations updates every 10 sec, in parallel, it sends this locations and others informations to a database. I managed to update the location while the app is in the background or when the phone is on standby. The app works fine for some days but for some reason that I cannot understand, the locations somehow stops while the phone is still running and the service still sends the other informations.

Is there a reason why the phone would stop request locations but still run the foreground service ?

The service is set as a Sticky service so it should restart if the memory runs out of space and the request update locations is triggered when the service is started.

The "Allow all the time" location setting is on for my app and like I said works fine for 2 to 3 days.

I was thinking about a problem concerning the battery charge not being sufficient to run location request, but didn't found anything on the subject so far.

I also tried a Wakelock to keep the app updating locations but didn't work.

  • Possibly similar question: [How can I disable the Android 11's auto-reset permissions globally?](https://android.stackexchange.com/q/244606/3573) but may help to know on which device / OS versions you are experiencing. Also FYI: https://dontkillmyapp.com/ – Morrison Chang Mar 09 '23 at 18:13
  • Hi @SimonPallais, did you finally solved the problem? I'm facing the same problem, GPS stops to return fresh positions and always returns the same last valid position during 1-2h, on a 6-8h tracking route. I've tried everything, request to avoid battery optimizations, using & refreshing wakelock PARTIAL_WAKE_LOCK, restart GPS provider subscription every 10 minutes... but something blocks the app from getting fresh positions for a while... we are testing on a Samsung A23 device. Thanks a lot for your feedback! – Pelanes Jul 21 '23 at 07:59

1 Answers1

1

For others still looking for answers. I faced the same problem. The answer is actually on the documentation.

You have to set the foregroundServiceType as stated on the documentation.

<service
          android:name=".MyMediaPlaybackService"
          android:foregroundServiceType="mediaPlayback"
          android:exported="false">
      </service>

Find more information on the link below:

https://developer.android.com/about/versions/14/changes/fgs-types-required

  • Hi @Abdulsalam Oladotun, do you recommend to use 'android:foregroundServiceType="mediaPlayback"' for a location service? I'm using type="location" for a location foreground service, but we are having the same problems, for a while, it stops returning fresh positions. Thanks – Pelanes Jul 21 '23 at 08:03