But we're supposed to be guaranteed that starter always runs, since as of (some B4A version) we are allowed do call suns located in started directly without CallSub/CallsubDelayedstarter service contains only initialization code, it may stop after starting
settings>developer options>running servicesHow do you check if it’s running or not?
since the starter service contains only initialization code, it may stop after starting
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
pw.PartialLock
n.Initialize
' // 2023.05.15
myTorch.Initialize
mod_functions.writelog("svc_service::Service_Create")
Starter.appset.currentChannel.Initialize
Starter.appset.currentChannel.listenChannel.Initialize
' // phone events
PE.InitializeWithPhoneState("PE",PhoneId)
' // set the serve hook to be called every 1 seconds
tmrServiceHook.Initialize("tmrServiceHook",1000)
tmrServiceHook.Enabled = True
Starter.appset.status_next_report = 0
Starter.appset.flp_next_report = 0
listenersLoaded = False
End Sub
Sub Service_Start (StartingIntent As Intent)
' // setup the notification
n = CreateNotification("Atlas PTT","Offline","icon_offline",Main,False,False,False)
Service.StartForeground(nID,n)
Starter.appset.notify.message = "Offline"
Starter.appset.notify.icon = "icon_offline"
Starter.appset.notify.id = nID
mod_functions.writelog("svc_service::Service_Start")
If Not(Starter.appset.currentChannel.IsInitialized) Then
Starter.appset.currentChannel.Initialize
Starter.appset.currentChannel.listenChannel.Initialize
End If
settNotification = 1
' // start the BR for spectralink smartphones
If Starter.appset.device_manufacturer = "Spectralink" Then
StartService(svc_spectralink)
End If
' // start the BR for spectralink smartphones
If Starter.appset.device_manufacturer = "Hytera" Then
StartService(svc_hytera)
End If
StartService(br_receiver)
End Sub
Sub Service_Create
mod_functions.writelog("svc_service::Service_Create")
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
pw.PartialLock
n.Initialize
PE.InitializeWithPhoneState("PE", PhoneId)
nNewPages.Initialize
tmrServiceHook.Initialize("tmrServiceHook",1000) '2000 ' 10000
sckPing.Initialize("sckPing")
serviceHelper = DateTime.Now + (DateTime.TicksPerSecond * serviceHelperFreq)
serviceHelper2 = DateTime.Now + (DateTime.TicksPerSecond * serviceHelper2Freq)
messageServiceKill = 0
End Sub
Sub Service_Start (StartingIntent As Intent)
mod_functions.writelog("svc_service::Service_Start")
n = CreateNotification("Atlas CM","Offline","app_logo_4_notification_bar_offline",Main,False,False,False)
' // setup the notification
Service.StartForeground(nID,n)
mod_functions.reset_mimimize
Starter.APPSET.charging = mod_functions.GetBatteryPlugged
' // start the login
If Starter.APPSET.LogoffUntil = 0 Then
Starter.APPSET.LoginReconnect = DateTime.now
End If
' // 2023.01.20
If Starter.APPSET.LoginReconnect > 0 Then
If Not(doLogin) Then
doLogin = True
End If
End If
' // get the active Network
Starter.APPSET.ActiveNetwork = mlWifi.ActiveNetworkType
' // 2024.02.15 - paused for testing
'StartService(svc_ping)
tmrServiceHook.Enabled = True
End Sub
Private Sub CreateNotification(Title As String, Content As String, Icon As String, TargetActivity As Object, _
AutoCancel As Boolean, Sound As Boolean, Vibrate As Boolean) As Notification
Dim nb As NB6
nb.Initialize(Application.PackageName,Application.LabelName, "LOW")
nb.SmallIcon(LoadBitmapResize(File.DirAssets, $"${Icon}.png"$,24dip, 24dip, True))
nb.AutoCancel(AutoCancel)
nb.OnGoing(True)
nb.SetDefaults(Sound, False, Vibrate)
Return nb.Build(Title, Content, Application.PackageName, TargetActivity)
End Sub
Yes. With a few exceptions, all services must be created while the app is on the foreground.Must a FGS be started from an Activity ?
Which of these are valid please:Yes. With a few exceptions, all services must be created while the app is on the foreground.