Android Question [SOLVED] Starter Service doe not appear in running services

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

The starter service does not appear in running services for one of our apps. What would the condtion be for this to happen. The app appears to funtion correctly.

Open to discussion

Regards

John.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
How do you check if it’s running or not?
since the starter service contains only initialization code, it may stop after starting
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
starter service contains only initialization code, it may stop after starting
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/CallsubDelayed
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
The reason for this question is as follows. I have 2 applications:

1. A PTT application that runs on all android versions, never gets killed and does not show starter as a running service under developer options>running services.
2. A Critical Messenger (CM) application, that runs on all versions of android up to 13, never gets killed and does show starter as a running service under developer options>running services. Under Android 14 this application is lucky to get 5-10 mins of run time. This happens on OnePlus 10Pro SDK34 and a Samsung S24(as reported by a customer).

On a Pixel 6a SDK 34 I have no issues with either application

The PTT app runs perfectly on the OnePlus 10 SDK 34.

Both apps use foreground services etc.

I am concerned at the moment as both apps are internally doing the same thing, but do not appear to be running the same.
 
Last edited:
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I have looked at the mylocation example and create the apk, it will be tested today on the OnePlus10 Pro SDK 34. In this app I do notice that the setserviceattribute is used.

In the PTT app we have that does not get killed, the service the is nothing special. Here are the create and start functions:

B4X:
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

In the app that is failing:

B4X:
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

Create notification for both is the same:
B4X:
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

I am not ask for a fix, I am just try to understand the where I could be going wrong. Also as mentioned before, both apps work flawlessly on a Pixel 6 SDK34
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Attached is the logcat file from the device is you search for criticalmessenger using notepad++ you will see what is going on.
 

Attachments

  • OnePlus10Pro_LogCat (004).zip
    262.3 KB · Views: 72
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
An Observation. If the screen remains on the app is not killed, once the screen is off for a peroid of time 5-8 mins the app is killed. Wild guess is it at all possible that the partial lock is not been given ?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Yes. With a few exceptions, all services must be created while the app is on the foreground.
Which of these are valid please:

A. That the main activity is in the foreground and the FGS is stared from the main activity e.g activity_resume::startservice(fgs)
B. That the main activity is in the foreground and the FGS can be started from starter.
C. That the main activity is in the foreground and the FGS can be started from a code module.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
So I finally tracked down the issue with the help of @OliverA .

On a onePlus phone with Oxygen14 (SDK34) when you request a partial lock, you are granted the lock. However the implementation that One Plus have used is you get 299,300 ms of time.

OplusWakeLockInfo { binderhash=23079791, flags=1, tag=B4A-Partial, duration=299300, starttime=413139511, packageName='com.islesystems.criticalmessenger', uid=10299, pid=29923}

When this time expires, your application is terminated beacuse you exceeded the allocated lock time. I have scoured the net and this rule does not appear anywhere. When I removed the partiallock, the application worked as expected.

In the FGS there is timer that tick's every second. From analyzing the logs and events that we send to one of our servers, I noticed that over a 10 minute period the timer lost 28 ticks out of 60(seconds)*10(mins) 600(seconds,10 mins) which is totally acceptable and did not impact the applications funtion.

I dont know if other manufacturers will go down the same route. If a partial lock is really needed, you could PL for 60 seconds, release for 10 seconds and PL again. This is probably a possible solution.

As @Erel pointed out Partial Locks have absolutly nothing to do with FGS(ForeGroundServices).

Regards

John.

P.S
Delighted to close this issue :)
 
Upvote 0
Top