Android Question Background location tracking without persistent notification?

Inman

Well-Known Member
Licensed User
Longtime User
As of Android 8.0 you need to start a service in foreground mode to prevent the system from killing it. This results in a persistent notification. I went through the background location tracking tutorial here.

https://www.b4x.com/android/forum/threads/background-location-tracking.99873/

I can see that it uses both Service.StartForeground (for persistent notification) and StartServiceAt (in case the service needs to be started again). Just like in the example, I also need the location data only every 30 minutes or so. My question is, in this case, can I omit Service.StartForeground (thereby eliminating the need for persistent notification) and just use StartServiceAt as I don't need the location data all the time and only at the exact time the service is started.
 

Inman

Well-Known Member
Licensed User
Longtime User
Yes. However while the service is running it should be a foreground service. This will happen automatically with the automatic foreground mode.

Note that StartServiceAt is not 100% reliable on all devices. It might run less frequently than scheduled.
Thanks Erel. So does this mean there is no way to hide the persistent notification and reliably get the location every 30 minutes in this case?
 
Upvote 0
Top