Hi, i am probably doing this wrong but i am trying to add a record to a database from within a service. Is this possible?
Any help will be appreciated
B4X:
'Service module
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 count As Int
Dim edtLat, edtLong As Float
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Service_Create
GPS1.Initialize("GPS")
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
End If
End Sub
Sub GPS_LocationChanged (Location1 As Location)
count = count + 1
ToastMessageShow("GPS Data" & Location1.Latitude & " " & Location1.Longitude, True)
addrec
GPS1.Stop
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 2 * DateTime.TicksPerMinute, False)
ToastMessageShow("Turning GPS ON", True)
GPS1.Start(0, 0) 'Listen to GPS with no filters.
count = 0
End Sub
Sub Service_Destroy
End Sub
Sub addrec
dbutils.CopyDBFromAssets("findem2.db")
Dim DBFileName As String : DBFileName = "findem2.db"
Dim DBFilePath As String : DBFilePath = File.DirDefaultExternal
Dim DBTableName As String : DBTableName = "location"
Dim a, b As EditText
Dim sql1 As SQL
a.Initialize("")
b.Initialize("")
a.Text= edtLat
b.Text= edtLong
sql1.ExecNonQuery2("INSERT INTO location VALUES(?, ?)",Array As Object(a.text, b.text))
End Sub
Last edited by a moderator: