I Inman Well-Known Member Licensed User Longtime User Nov 5, 2019 #1 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Nov 5, 2019 #2 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. Upvote 0
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.
I Inman Well-Known Member Licensed User Longtime User Nov 5, 2019 #3 Erel said: 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. Click to expand... 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
Erel said: 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. Click to expand... 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?
Erel B4X founder Staff member Licensed User Longtime User Nov 5, 2019 #4 The user will not see the notification as it will only appear for a few seconds until the location data is available. Upvote 0
The user will not see the notification as it will only appear for a few seconds until the location data is available.
I Inman Well-Known Member Licensed User Longtime User Nov 5, 2019 #5 Erel said: The user will not see the notification as it will only appear for a few seconds until the location data is available. Click to expand... Cool. Thanks Erel. Upvote 0
Erel said: The user will not see the notification as it will only appear for a few seconds until the location data is available. Click to expand... Cool. Thanks Erel.