Android Question How can I detroy GPS service after finished the job

Richard Goh

Active Member
Licensed User
Longtime User
I had a gps service to do some jobs. How can I destroy or close the service after each job is completed. The service is called from activity and in the service itself will call activity sub function to do updating. I need this is because somethime the application will some sort like hanged after calling GPS service. That's why I need it to be closed before calling another GPS service again.
 

Richard Goh

Active Member
Licensed User
Longtime User
my code
call service using CallSubDelayed2(GPSService, "StartGPS", jobId)
GPSService
Sub Process_Globals
' 'These variables can be accessed from all modules.
Private GPS1 As GPS
Dim GPS_On As Boolean : GPS_On = False
Private jID As String
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
If GPS_On = True Then
GPS1.Stop
End If
End Sub
Sub StartGPS(docID As String)
GPSDocID = docID
If GPS1.IsInitialized = False Then
GPS1.Initialize("GPS")
End If
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
firstNode = True
parser.Initialize
GPS1.Start(0, 0)
End If
End Sub
Sub GPS_LocationChanged (Location1 As Location)
If GPS_On = False Then
Main.gpsLat = NumberFormat(Location1.Latitude, 1, 6)
Main.gpsLong = NumberFormat(Location1.Longitude, 1, 6)
saveLocation
End If
End Sub
Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
Sub GPS_GpsStatus (Satellites As List)
End Sub
Sub saveLocation()
GPS_On = True
GPS1.Stop
End Sub
 
Upvote 0
Top