I am a bit confused about how services function, notably these two things:
From http://developer.android.com/guide/topics/fundamentals/services.html :
A service is “started” when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed.
and:
Caution: A 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).
My questions:
-
How is it possible for a service that was started by startService() survive, if the main Activity thread quits? Or only those services survive the main Activity shutdown, that are in a separate thread?
-
How can I start a service in a separate thread? The dev doc at http://developer.android.com/guide/topics/fundamentals/services.html#ExtendingService only shows an example how to spawn a thread when the service is created…not how to spawn the service itself in a new thread…
EDIT: Isandroid:process=in manifest.xml used for starting it in a separate thread? (if it starts it in a new process, then it must be in a separate thread..)
To quote you,:
When the main activity is shutdown, it does not necessarily mean the hosting process exits. According to the documentation, the service continues to run because the process is alive!
Check this
So on only when running low on resources and it is required to kill processes lying around, your process would be killed. Else. the process lives on so would your service.