androidbackgroundgpslocationlocation-services

Gps updates in background for long time


I have implemented a foreground service to get GPS updates for longer runs, like 3 hours, when the app is in background. It is our business requirement. But the app stops getting updates after a few minutes. I see the "location icon" on top bar go disappear, even though my foreground service notification is still there.

I have also excluded my app from Battery Optimization list from the settings, so that Android doesn't kill my app. It helps to keep gps updates alive for about half an hour only, then again the location icon goes away and i stop getting gps updates.

What can I do to keep it always ON?


Solution

  • I am posting this answer based on my short comment and OP request

    You can start that service by separate process by adding android:process=":FusedLocationService" in your Service component in manifest.xml.

    I had done this and work in most of the device except some of the manufactures like Honor and other because they customized Android AOSP for better user experience