سؤال

What is the difference between accessibility service and background service? When should I use each other?

هل كانت مفيدة؟

المحلول

The two serve different purposes entirely:

Background Service - Unless you specify otherwise, most of the operations you do in an app run in the foreground on a special thread called the UI thread. This can cause problems, because long-running operations will interfere with the responsiveness of your user interface. This annoys your users, and can even cause system errors. The Androind framework allows you to run these sorts of operations in a background thread.

Accessibility - Many Android users have different abilities that require them to interact with their Android devices in different ways. These include users who have visual, physical or age-related limitations that prevent them from fully seeing or using a touchscreen, and users with hearing loss who may not be able to perceive audible information and alerts.

An accessibility service runs in the background and receives callbacks by the system when AccessibilityEvents are fired. Such events denote some state transition in the user interface, for example, the focus has changed, a button has been clicked, etc. Such a service can optionally request the capability for querying the content of the active window. Development of an accessibility service requires extending this class and implementing its abstract methods.

Use accessibility if you think users will need special assistance with your app. Use background for long running tasks to keep your UI snappy.

نصائح أخرى

A background service allows execution when the UI is not present (while the app is "closed" for instance). It can acquire the "foreground priority" to be able to be kept alive in the long-term, by displaying a long-standing "foreground" notification to the user. "Foreground/Background" priority happens at the process level, not the thread one. A background service does not improve UI responsiveness, as it uses the main/ui thread as much as any Activity. Any other thread can be used to solve UI lack of responsibility.

Accessibility service is the same, although it receives a special kind of event corresponding to the user's interactions on top of that and requires to be manually setup by the user through the settings (it cannot be activated programmatically). It does not need a foreground notification.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top