Android API文档翻译——Service

来源:互联网 发布:两棵枣树 知乎 编辑:程序博客网 时间:2024/05/17 03:34

概述:

声明一个Service(或其子类)组件。与Activity不同的是,Service是非可见的。他们常用于实现长驻后台的操作或为其他Application提供类似WebService的交互接口。

所有的Service必须在manifest配置文件中通过<service>标签来声明。如果没有声明的话,则不会在system中看到,而且永远不能被运行。

 

参数:

android:enabled

  Service是否能被系统初始化,默认为true。(具体什么叫被系统初始化,还需要研究)

  <application> and<service> 的enable属性必须都为true,该Service才能被系统初始化,缺一不可。 当然,默认情况下就是true,所以一般也不用设置。

 

android:exported

标识该组件是否可以被其他应用程序调用,或者与其交互。

该参数的默认值取决于<service>是否包含<intent-filter>,如果不包含,则默认值为false,反之则为true。

这个参数并不是唯一可以限制Service入口的参数。你也可以使用permission权限控制来达到相同的目的。

 

android:icon

说白了就是在进程菜单中显示该Service的Logo。

 

 

android:label

   说白了就是在进程菜单中显示该Service的Name。

 

android:name

    就是你的implements了Service类的实现类。他既可以是一个类全名,也可以只包含类名。注意:该属性没有默认值,必须被明确声明。

 

android:permission

    标识此Service的调用权限,如果没有设置,则默认使用<application>的权限设置。

 

android:process

标识该Service将运行在哪个进程中。一般来说,所有的组件都会默认运行在创建它们的Application中,名称跟包名相同。(设置为system是什么意思?)

If the name assigned tothis attribute begins with a colon (':'), a new process, private to theapplication, is created when it's needed and the service runs in that process.If the process name begins with a lowercase character, the service will run ina global process of that name, provided that it has permission to do so. Thisallows components in different applications to share a process, reducingresource usage.

原创粉丝点击