Accessibility Service's 'onAccessibilityEv

2019-02-19 19:56发布

问题:

I've run into a rather unfortunate problem with an application I'm developing that utilizes an accessibility service to do some special handling of notifications when they arrive on a user's device. The thing is, it works just fine, but the service's 'onAccessibilityEvent' function is never invoked unless the service is restarted from Android's Accessibility page, i.e. I must first enable the service from that page, then disable it, then enable it again in order for 'onAccessibilityEvent' to be called at all.

I've tried using Google's example without making any changes of my own, but even then I still appear to be experiencing the same issue, so I'm not sure what to make of what's going on here. Has anyone run into this problem?

回答1:

This is because the Service is being killed by the Android framework which requires restarting it from the accessibility menu.

Youcan validate this by adding logs in onDestroy() method



回答2:

This happens probably for a android bug as it is solved in newer android version. when you power off onUnbind is called. But on_boot_finished onRebind is not called, so your service remains useless. I have provided my solution to this problem here, please check this out.