Android Question Missing Service_Create ?

marcick

Well-Known Member
Licensed User
Longtime User
I'm debugging to find a bug and I have discovered this:

I have the starter_service that start another service "TestServ"

B4X:
#Region  Service Attributes
    #StartAtBoot: true
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Private logs As StringBuilder
    Private logcat As LogCat
End Sub

Sub Service_Create  
    logs.Initialize
#if RELEASE
    logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
#end if
End Sub

Sub Service_Start (StartingIntent As Intent)
    if some_conditions then
        StartServiceAt(TestServ, DateTime.Now + 5 * DateTime.TicksPerSecond, True)
    End If
End Sub

When I reboot the device, I see that the starter service is executed, but then only the Service_Start of TestServ is called, the Service_Create is missing
If I terminate the app and launch again, Now I see both Service_Create and Service Start of TestServ executed.

The missing Service_create od TestServ appear only at first boot

Is that possible or am I in tilt ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Yes Erel, I have three confirmations:
I can't see "service_create" in the log window.
I can't see my added log.
The app crash because the part of code that is in service_create is not executed.

This happens only at boot. Second time I launch the app all is ok.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I have attached a test app that show this.
Reboot the device, connect it to the logger and you see only the TestServ_Start, not the TestServ_Create
 

Attachments

  • TestServ.zip
    7.1 KB · Views: 127
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
That was my previous solution.
But because TestServ need to be started at boot upon certain conditions, I wanted to put that check in the starter service, instead autostart TestServ and then destroy it if the conditions are not met.
Ok, I come back to the previous solution.
Can you confirm that the starter service can't be used to correctly start another service ?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Can you confirm that the starter service can't be used to correctly start another service
(And please could you explain (in short, I don't want to abuse), why it could not be used. Thanks)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The application always starts with a "target" module. In most cases it is the main activity. In other cases such as widgets or applications that start at boot the target module is one of the services.

The OS starts the target module. The target module internally starts the starter service which eventually calls the target module again.
So there is an assumption that there are two different modules: the target module and the starter service. You can start other services from the starter service however the starter service should not be the target module.

But because TestServ need to be started at boot upon certain conditions, I wanted to put that check in the starter service, instead autostart TestServ and then destroy it if the conditions are not met.
There are no advantages for doing it from the starter service.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
So, If I understand well, the starter service should never have the SrartAtBoot true, correct ?
 
Upvote 0
Top