Question

How does an AccessibilityService differ from a normal Service in regards to memory management by the system?

What I am asking is: can the system kill an AccessibilityService for saving memory and, if so, when you go to the Accessibility Settings would you see it turned on or off? Will the user have to turn it on manually again?

Would using startForeground help keep the AccessibilityService alive?

In a similar question, after a restart, my AccessibilityService is not called (onServiceConnected is never called). When I go to the Accessibility Settings, the service shows it as being turned on. I have to turn it off and turn it on for it to work again. Any ideas?

Was it helpful?

Solution

You do not need to use foreground notifications for an AccessibilityService to stay running in the background. It is a special case of Service.

The framework will attempt to automatically restart your accessibility service if it crashes. If it crashes multiple times, it will take longer each time to restart. This may be why it appears that your service is enabled, even though it is not running.

OTHER TIPS

Take a look here: http://developer.android.com/guide/components/processes-and-threads.html .

Since AccessibilityService is indeed a Service, it can be killed like any other Service. Since it should be a bound service, it keeps beeing alive as long as there is an Activity bound to it. If your Activity doens't unbind from it in onPause() or onStop(), then it will still be bound when resumed. This implies that onServiceConnected() will not be called. You can still use the IBinder you returned in the onBind() call.

Read also "Additional notes" here: http://developer.android.com/guide/components/bound-services.html#Binding.

Using etForeground() helps keeping it alive giving it the highest priority possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top