The GPS has to be in a background service, because :
1- Android will either stop or intercept the apps that use too much memory
2- Android has a feature called battery optimization which will prevent your app to work properly if you use these type of functions in the UI and not in the background service
We have built a tracking system for a very large company, and after a while they started reporting this problem.
using the background service solved this issue for us.
a tip :
use lower gps interval example : 5-10 ms to get better results.
The app is always in the foreground, with the display always active, the phone is normally always connected to a power cable
Gps code (initialization, start, stop, reading,..) is under service module section
Sub Process_Globals
Public GPS1 As GPS
End Sub
Sub Service_Create
GPS1.Initialize("GPS")
StartGps
End Sub
Public Sub StartGps
Try
GPS1.Start(0, 0)
Main.gps_on=1
Catch
Main.gps_on=0
End Try
End Sub
Sub GPS_LocationChanged (Location1 As Location)
Try
Private pagGps As frmGps
pagGps = B4XPages.GetPage("gps")
CallSub2(pagGps, "LocationChanged", Location1)
Catch
Log(LastException)
End Try
End Sub
What do you mean 'that use too much memory'?
How can I tell if my app is using 'too much memory'?
And how can i make sure if android shuts down my app for this reason?
The 'battery optimization' feature has been expressly disabled on the app
What do you mean by 'use lower gps interval' ?
Currently with the vehicle in motion, the GPS returns a position approximately every second
Of all these points we only use one point every 60 seconds
How do you get a reading every 5ms (200 readings / sec)?