Sam Sam - 1 year ago 231
Android Question

How can I programmatically start and stop an AccessibilityService?


I have an app that has an
. Android seems to keep
s running all the time, but I only need mine to run sometimes. (Specifically, if a user opens my app and turns it off, the
is no longer needed.)

If my
is running when it isn't needed, it's wasting the device's RAM and CPU, and I want to avoid doing this to my users if possible.


How can I programmatically start and stop my

Note that I am not asking to programmatically enable or disable the
in Android's accessibility settings; this is just about starting and stopping it when it's already enabled.

What I've tried (stopping the

Related questions

Sam Sam
Answer Source

Taken from the Lifecycle section of the AccessibilityService documentation:

The lifecycle of an accessibility service is managed exclusively by the system and follows the established service life cycle. Starting an accessibility service is triggered exclusively by the user explicitly turning the service on in device settings. After the system binds to a service, it calls onServiceConnected(). This method can be overriden by clients that want to perform post binding setup.

An accessibility service stops either when the user turns it off in device settings or when it calls disableSelf().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download