先看下官方网页上的说明:
1、http://developer.android.com/reference/android/app/Service.html
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding <service>
declaration in its package's AndroidManifest.xml
. Services can be started with Context.startService()
and Context.bindService()
.
Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work. More information on this can be found in Processes and Threads. The IntentService
class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.
If we want to make this service run in a remote process (instead of the standard one for its .apk), we can use android:process
in its manifest tag to specify one:
<service android:name=".app.MessengerService" android:process=":remote" />
Note that the name "remote" chosen here is arbitrary, and you can use other names if you want additional processes. The ':' prefix appends the name to your package's standard process name.
2、http://developer.android.com/intl/zh-CN/guide/topics/manifest/service-element.html
-
The name of the process where the service is to run. Normally, all components of an application run in the default process created for the application. It has the same name as the application package. The
<application>
element'sprocess
attribute can set a different default for all components. But component can override the defaultwith its ownprocess
attribute, allowing you to spread your application across multiple processes.If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, 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 in a global process of that name, provided that it has permission to do so.This allows components in different applications to share a process, reducing resource usage.
android:process