Android Question How to tell what started a service?

GuyBooth

Active Member
Licensed User
Longtime User
I have a service that may be started three different ways, and I need, from within that service, to determine which of the three possible ways it was started. The first way is from Boot, and I know how to do that:

If StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" then....

The other two ways are from another service or from an activity. Is there a way to determine the name of the Activity or the name of the service that started it?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a way to determine the name of the Activity or the name of the service that started it?
Not if you are using StartService(ServiceName).

You can however manually create an intent with a custom action and send it to the service:
B4X:
Dim i As Intent
i.Initialize("FromMainActivity", "")
i.SetComponent("<package name>/.<service name (lower cased)>") 'example "b4a.example/.service1"
StartService(i)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You can set a global variable containing the process which started your service.
 
Upvote 0
Top