Service Module

walterf25

Expert
Licensed User
Longtime User
Hello all, i need some help, i'm working on an app that requires a service module in order to submit coordinates every so often to a server.

So far everything works good as expected, except that when the service starts, and i enable the gps and it starts checking for the current location, and then i do a get request to submit the coordinates to the server, the service runs great for about 5 minutes, i have the service re-schedule itself every 30 seconds, but after 5 minutes or so, it just goes crazy, and it starts running continuously about every 1 second, i need to find out why this is, after all i'm re-scheduling the service every 30 seconds not every 1 second.

here is my code

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
Dim gps1 As GPS
Dim sendcoordinates As String 
Dim username, password As String 
Dim db As SQL 
 Dim Cursor1 As Cursor
 Dim cursorposition As Int 
End Sub
Sub Service_Create
gps1.Initialize("gps1")
Log("GPS_Tracker Service started")
If gps1.GPSEnabled = False Then StartActivity(gps1.LocationSettingsIntent)
db.Initialize(File.DirInternal, "cyprus.db", False)
Cursor1 = db.ExecQuery("SELECT UserName, Password FROM logininfo")
'gps1.Start(0, 0) 'Listen to GPS with no filters.
End Sub

Sub Service_Start (StartingIntent As Intent)
gps1.Start(0, 0)
Log("finding location....")
StartServiceAt("", DateTime.Now + 30 * 1000, True)

Sub GPS1_LocationChanged (Location1 As Location)
Dim coordinates As HttpJob
coordinates.Initialize("location", Me)
Dim time1 As String
ToastMessageShow(Location1.Latitude & " " & Location1.Longitude, False)
Log(Location1.Latitude & " " & Location1.Longitude)
 Log(Location1.Speed * 3.6)
   gps1.Stop
   DateTime.DateFormat = "yyyy-MM-dd-HH:mm:ss" 
   time1 = DateTime.Date(DateTime.Now)
 
   cursorposition = Cursor1.RowCount - 1
   Cursor1.Position = cursorposition
   
    username = Cursor1.GetString("UserName")
   password = Cursor1.GetString("Password")
   'Next
sendcoordinates = "http://xxxxxxxxxxxxx.net/tracking/controller.php?action=coordinate_update&username=" & username & "&password=" & password & "&i_user_id=3&s_lat=" & Location1.Latitude & "&s_long=" & Location1.Longitude & "&s_accuracy=5" & "&s_speed=" & (Location1.Speed * 3.6) & "&d_time=" & time1 & "&b_from_saved=0"
Log(sendcoordinates)
coordinates.Download(sendcoordinates) 
End Sub

End Sub

any thoughts anyone?

It doesn't happen all the time, but i have seen it do this a few times.

thanks everyone!

Walter
 
Top