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).
CommandBusexpose some reactive way to get commands to the service. If you were using Kotlin, that could be a
SharedFlow. Since you are using Java, that could be an RxJava
Observable, or perhaps a simple callback.
MyAccessibilityServiceget access to the
CommandBussingleton and use whatever you set up in step #2 to find out about commands.
CommandBusexpose an API to hand it commands to deliver to the service (e.g., a
MyBroadcastReceiverget access to the
CommandBussingleton and call the method from step #4 in
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.