My code is currently written with the intention that it will never stop, with a routine called Run_CalCheck in the service MTO_Run that is executed once every 5 minutes. The code is set up like this:
In the Starter Service:
There is a Main with a user interface, which doesn't have to be used for the program to run.
In a Service called MTO_Run, which starts at boot, the code is like this:
My question is:
Do I have to have the PhoneWake.PartialLock statement that I have included in the Starter Service? If I remove it, is the program guaranteed to run every 5 minutes even when the phone sleeps?
In the Starter Service:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public PhoneWake As PhoneWakeState
Private CalCheckmSecsInterval As Long
Private CalCheckMinsInterval As Long : CalCheckMinsInterval = 5 ' This is the interval between each running of the CalCheck service
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
' Convert the interval to millisecs
CalCheckmSecsInterval = CalCheckMinsInterval*60*1000
' Make sure the device doesn't sleep
PhoneWake.PartialLock
End Sub
Sub Service_Start (StartingIntent As Intent)
CalCheck_Timer
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub CalCheck_Timer
CallSubDelayed(MTO_Run, "Run_CalCheck")
Sleep(CalCheckmSecsInterval)
' Reiterate
CalCheck_Timer
End Sub
There is a Main with a user interface, which doesn't have to be used for the program to run.
In a Service called MTO_Run, which starts at boot, the code is like this:
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
'
Sub Service_Destroy
End Sub
Sub Run_CalCheck
' Some code
End Sub
My question is:
Do I have to have the PhoneWake.PartialLock statement that I have included in the Starter Service? If I remove it, is the program guaranteed to run every 5 minutes even when the phone sleeps?