Restart Accessibility Service After Crash
In my Application there is a Service and an AccessibilityService. Now the Service is bound by the accessibility Service in order to receive information. My Service periodically che
Solution 1:
Why when the AccessibilityService crashes does the Android OS not restart it?
I don't know, but I suspect there isn't much you can do about this. I've had similar problems with AccessibilityServices, so I think this is normal behaviour. The best I can think of is:
- Carefully write your
AccessibilityServicecode and thoroughly test it so that it doesn't contain any bugs that will cause it to crash. - Don't do any logic in your
AccessibilityServicethat you could also do in a different place. The less work yourAccessibilityServiceis doing, the simpler it is, so the less likely it is to have bugs. - Make your
AccessibilityServicecode error-tolerant. Predict errors that will happen inside the service, and write code to catch them and recover from them so that theAccessibilityServicecontinues running normally if possible. - Run your
AccessibilityServicein its own process so it isn't killed when your other code crashes. Note that this might be difficult depending on how the service interacts with the rest of your code.
Can I change my code to check if the AccessibilityService is enabled but also has a running instance?
Yes; there are a couple of common techniques to do this. See How to check if a service is running on Android?.
Post a Comment for "Restart Accessibility Service After Crash"