I asked a couple of times for concrete scenarios, and you did not really provide any, so I am going to answer with an abstract scenario: suppose that your broadcast is designed to send a command to the service.
In that case, you could:
Implement a singleton (here called
CommandBus
, for lack of a better idea of a name). Ideally, that singleton would be set up by a dependency inversion framework (e.g., Dagger/Hilt).Have
CommandBus
expose some reactive way to get commands to the service. If you were using Kotlin, that could be aSharedFlow
. Since you are using Java, that could be an RxJavaObservable
, or perhaps a simple callback.Have
MyAccessibilityService
get access to theCommandBus
singleton and use whatever you set up in step #2 to find out about commands.Have
CommandBus
expose an API to hand it commands to deliver to the service (e.g., asendCommand()
method).Have
MyBroadcastReceiver
get access to theCommandBus
singleton and call the method from step #4 inonReceive()
.
At this point, when MyBroadcastReceiver
receives a broadcast, it tells CommandBus
to send the command, which then flows over to MyAccessibilityService
, which goes and does something.
CLICK HERE to find out more related problems solutions.