Good day dear programmers. (I use Google as a translator, so do not swear strongly) Briefly, there is an oreo and you need a service that will check a certain URL every 20 seconds and cause a certain action. But the current code does not work much time, oreo kills it. What not so please tell me. Thank.
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
Dim pw As PhoneWakeState
Dim n As Notification
End Sub
Sub Service_Create
Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_ALWAYS
End Sub
Sub Service_Start (StartingIntent As Intent)
pw.PartialLock
Service.StopAutomaticForeground
n.Initialize
n.SetInfo("Check data", "Run",Main)
Service.StartForeground(1,n)
Log("run")
Wait For (check) Complete (Result As Int)
StartServiceAt("",DateTime.Now+20*DateTime.TicksPerSecond,True)
Service.StopAutomaticForeground
End Sub
Sub Service_Destroy
End Sub
Private Sub check() As ResumableSub
Dim j As HttpJob
j.Initialize("",Me)
j.Download("http://www.site.com/data.txt")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("ok")
Dim str As String=j.GetString
End If
j.Release
Return 1
End Sub