Syntax
<Service android: enabled = ["true" | "false"]
Android: exported = ["true" | "false"]
Android: icon = "drawable resource"
Android: isolatedProcess = ["true" | "false"]
Android: label = "string resource"
Android: name = "string"
Android: permission = "string"
Android: process = "string">
...
</Service>
Parent Element
<Application>
Child Element
<Intent-filter>
<Meta-data>
Description
Declare a service as a subclass of the application component ). Unlike activities, services lacks Visualized User interfaces. They are used to implement long-term background operations or rich communication APIs called by other applications.
All services must be represented by the <service> element in the manifest file. What is not declared in manifest will be invisible to the system and will never run.
Attribute
Android: enabled
Whether the service can be instantiated by the System-true if yes; otherwise, false. The default value is true.
<Application> An element has its own enabled attribute that can be applied to all application components, including services. If the service is enabled, the <application> and <service> attributes must be true (both of them are default values ). If one of them is false, the service will be disabled; it will not be instantiated.
Android: exported
Whether other application components can call this service or interact with it-true if yes; otherwise, false. When the value is false, only components of the same application or applications with the same user ID can start the service or bind it.
The default value depends on whether the service contains intent filters. The missing filter means that it can only be called by specifying its exact class name. This means that this service can only be used inside the application (because other applications do not know the class name ). Therefore, in this case, the default value is false. On the other hand, at least one filter means that this service can be used externally. Therefore, the default value is true.
This attribute is not the only way to restrict this service from being exposed to other services. You can also restrict external entities that interact with the service through permissions (see permisson attributes ).
Android: icon
Service icon. This attribute must be set to reference drawable resources that contain images. If it is not set, the application icon replaces it (see the icon attribute of the <application> element ).
For all intent filters, whether set by yourself or by <application>, are their default icons (see the icon attribute of the <intent-filter> element ).
Android: isolatedProcess
If it is set to true, the service runs in a special process, which is independent from the rest of the system and has no permissions. The only communication method is through this Service API (binding or starting ).
Android: label
The name displayed by this service to the user. If this attribute is not set, use the label attribute of <application> instead (see the label attribute of the <appliation> element ).
The label of this service, whether set by itself or by application, is the default value for the intent filters of this service (see the label attribute of the <intent-filter> element ).
This label should be set as a string resource reference, so that the user interface can be localized like other string resources. However, it can also be set as a raw string for convenience during application development.
Android: name
The name of the service subclass that implements this Service. This should be a full-format Class Name (for example, "com. example. project. RoomService "). However, if the first letter of the name is a vertex (for example, ". RoomService"), it is added to the end of the package name declared in the <manifest> element.
Once you publish your application, do not modify this name (unless you have set android: exported = false ).
No default value. This name must be specified.
Android: permission
The name of the required permissions to start the service or bind it to an object. If the caller of startService (), bindService () or stopService () has not obtained the authorization, these methods will not work and the intent object will not be passed to the service.
If this attribute is not set, the permission set by the permission attribute of the <application> element will be applied to this service. If none of them are set, this service will no longer be protected by permissions.
Android: process
Name of the process to be run by the Service. Generally, all components of an application run in the default process created by the application. Just like the application package name. <Application> the process attribute of the element can set different default values for all components. However, a component can override the default value through its own process attribute, allowing you to expand your application to span multiple processes.
If the name assigned to this attribute starts with a colon (:), a new process that is private to the application will be created when it is needed, at the same time, this service is running in which process. If the process name starts with a lowercase letter, the service runs in the global process. This allows components in different applications to share the process and reduce resource consumption.