I have created an android Service
, which extends an AccessibilityService
. From my Activity
, I would like to bind to that Service
. Because I need to send information from Service
to Activity
. I need example code please. I have searched google and have not found anything similar, someone could put a link to an example please.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
While binding with an AccessibilityService from an Activity is possible, you'll only be able to pass AccessibilityEvents into the service. This is because AccessibilityService.onBind() is declared final, which means you won't be able to add any new methods to the binder.
There are, however, several alternative solutions.
If your activity and service are running within the same process (this is typically true if they are in the same APK), then you can communicate with a static instance of your accessibility service. Here is an example of how that would work:
MyAccessibilityService.java:
MyActivity.java
If your service and activity are in separate processes (e.g. separate APKs), then you still have a few options:
If you need elaboration on either of those, leave a comment.
Maybe there is another way to communicate whith each other:
At
AccessibilityService
Child Class:At
target Activity
:just invoke the specific EventTypeSample Code: