I am new to Android. Right now I am just trying some examples which includes Services. In one of the example, service is created as a separate background process. Using something like this
android:process=":background"
They said now service will be having separate process environment and thus it is separate from the one(Application) that is started it. When I killed the parent process i.e.Application, the service is also getting killed. Is this normal behavior or not? Because what I understand from that article is Service wont get affected since it is different process environment. Please correct me if I am wrong. Thanks in advance
UPDATE: Even I saw the same behavior if I use :remote.
Service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise.
Android might decide to shut down a process at some point, when resources are required by other processes that are more immediately serving the user. Application components running in the process that's killed are consequently destroyed.
A service is started when component (like activity) calls startService() method, now it runs in the background indefinitely. It is stopped by stopService() method. The service can stop itself by calling the stopSelf() method.
Just a copy from the Android document:
If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed. If the process name begins with a lowercase character, a global process of that name is created. A global process can be shared with other applications, reducing resource usage
http://developer.android.com/guide/topics/manifest/application-element.html#proc
Afaik, there are two types of services,
1) background : which run in the same process of your application.
2) Remote :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: ,
we can also use other strings then background and remote. here is service lifecycle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With