Service starting problem....

PaulR

Active Member
Licensed User
Longtime User
Hi, I am trying to start a service unsuccessfully in my app.

I can create a simple app that creates a service okay, but for some reason the code is not being called in the one I am working on.

I am calling StartService(nameOfServiceModule) in Activity_Create with Logs in the various service subs, but I am not getting anything output from the Logs in the Service (I am in the simple test app).

So part of the code is....

Main
B4X:
Sub Activity_Create(FirstTime As Boolean) 

Log("Activity_Create - About to StartService")
   StartService(audioPlayerService)

ServiceModule (called audioPlayerService)
B4X:
Sub Service_Create
   
   Log("audioPlayer - Service_Create")
   
End Sub

..........................

Sub Service_Start (StartingIntent As Intent)
   
   serviceStarted = True
   Log("audioPlayer - Service_Start")
In the logs, I am getting the one just before StartService, but none of the Service ones.

Would there be anything anyone is aware of that would break starting a service?
 

abdulla

Member
Licensed User
Longtime User
I Believe that you should do StartService("ServiceName") this way :

StartService("audioPlayerService")

you are missing the quotations around the service name,

i hope it works , good luck
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Thanks, but that is not the problem. I have tried that, and this test app works....

Main
B4X:
'Activity module
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 Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   StartService(audioPlayer)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   StopService(audioPlayer)
End Sub

Service
B4X:
'Service module
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
   Log("In Service_Create")
End Sub

Sub Service_Start (StartingIntent As Intent)
   Log("In Service_Start")
End Sub

Sub Service_Destroy
   Log("In Service_Destroy")
End Sub
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Thanks, it turns out the issue was that I had checked Do Not Overwrite Manifest file after trying to enable global hardware acceleration before implementing the new service.

Now it is nearly working. :)
 
Upvote 0
Top