I have problem with stopping GPS sometimes. If I use it in activity then start & stop works ok, but I had to separate it between activity and service like this:
GPS is started normaly, and after app closes GPS1.Stop is called, but GPS sensor thus not stop working (GPS icon in notification bar still working). What is wrong here?
B4X:
ACTIVITY:
Sub Activity_Create(FirstTime As Boolean)
StartService(Service1)
End Sub
SERVICE1:
Sub Service_Create
'PUT SERVICE IN FOREGROUND STATE - SO THAT SERVICE WILL NOT BE KILLED BY OS
Log(" put service to foreground")
Dim sNotif As Notification
sNotif.Initialize
sNotif.Icon = "icon" ' empty string will cancel notification ...
sNotif.OnGoingEvent = True
sNotif.SetInfo("PD","Service Running",Main)
sNotif.Sound = False
sNotif.Vibrate = False
sNotif.Notify(1)
Service.StartForeground(1,sNotif)
End Sub
Sub Service_Start (StartingIntent As Intent)
'ENABLE GPS
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device", True)
StartActivity(GPS1.LocationSettingsIntent)
Else
GPS1.Start(1000,0) 'Listen to GPS with no filters
End If
End Sub
Sub Service_Destroy
GPS1.Stop
Log(" GPS1.Stop")
End Sub
GPS is started normaly, and after app closes GPS1.Stop is called, but GPS sensor thus not stop working (GPS icon in notification bar still working). What is wrong here?