Android Question Background tracking help

web-yacht

Member
Licensed User
Longtime User
Hi,
I'm working on an app that needs to log gps position in background.
I've followed example at https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
it works but the problem is that after few minutes (variable 2-10 minutes) the service stops.

I also tried an app without gps, with a service that plays a beep every 10 seconds, same behaviour, after some minutes the service stops.
I'm testing on android 7 and android 8, in release mode and outdoor for gps version

Thank you for any support
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

web-yacht

Member
Licensed User
Longtime User
How do you see that the service stops?

because in the tracker service i send the gps position to a server, and after few minutes it stops sending data.
and also beacuse the notification icon disappears.

On some devices you just can't run in the background. You might be able to whitelist the app in the device settings.

ough, that is a problem, any workaround to obtain background tracking position?

thank you
 
Upvote 0

web-yacht

Member
Licensed User
Longtime User
What device exactly are you using?

I'm developing on a Xiaomi redmi 4x, but i've tested on different devices

Add you app to the whitelist in the device if there is one. Most users telling about this problem are using Huawai devices.

I'will check, where is the whitelist in setting?
But it is not suitable for end user to have to do with app settings, is there a way to ask for "background permission" like other permissons?

something like
B4X:
Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)

The intent of the app is to track user movements by walk or bycicle, so it will be useful log position every 10-15 seconds.
Obviously, if the app is in foreground everything works, but it would not be very comfortable

Thank you for your support
 
Upvote 0

web-yacht

Member
Licensed User
Longtime User
thank you for your support
so, i restarted from beginning,
- downloaded the "background location tracking" example from https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
- installed release version on xiaomi redmi7a android 9 (i disabled lockscreen to be able to monitor the app)
- first test: with app in foreground, it runs continuously for more then 20 minutes, the notification is updated and gps icon remains in status bar
- second test: after launching the app, tapped the home button and after about 2 minutes the gps icon disappears and the notification with coordinates stop updating
- third test: after launching the app, tapped the back button and after about 2 minutes the gps icon disappears and the notification with coordinates stop updating

I don't know if could be helpful but i notice this behaviour:
after the third test i waited about 30 minutes and i have seen the notification updated but without coordinates (only "..."). so i think the service it is restarted but without activating the gps...
 
Upvote 0

web-yacht

Member
Licensed User
Longtime User
Hi, thank you Erel.

Yesterday i found the way, in the app settings there is an option called "battery saver" and if setted to "no restrictions", the app works in background.
I've tested on one device overnight and it worked for about 8 hours, then it stopped.
I will do more test.
The "battery saver" setting has an option to treat important app selectively (default option), i will try to understand what apps are "important".

My problem now is how to explain to end user, to do a right setting on different devices.
I would like to have a selfsetting app without any complexity with system settings.

Anyway, thank you for all your support
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…