I'm using the simple test service below. It works properly but after 10 passes it just keeps going to x= 11, 12.... Calling StopService does call Service_Destroy. The service is called from an activity as in the first code example. How do I make it stop and return to the calling activity?
B4X:
Sub ServiceTestButton_Click
StartService("FindProxUsers")
End Sub
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim x=0 As Int
Dim n As Notification
End Sub
Sub Service_Create
n.Initialize
n.Icon = "icon"
n.Light = True
n.AutoCancel = True
End Sub
Sub Service_Start (StartingIntent As Intent)
x=x+1
n.SetInfo("X = " & x , "Click here to close notification", "BTAsyncStream")
n.Notify(1)
If x = 10 Then
StopService("")
End If
StartServiceAt("",DateTime.Now + 10 * 1000, True)
End Sub
Sub Service_Destroy
n.SetInfo("Service has ended.", "Click here to cancel", "BTAsyncStream")
n.Notify(1)
End Sub