Why does a service not run in it's own thread under Android? And what were the design considerations?
-
I don't know why it's not running, but you can create service in another process or use IntentService, which running in another thread. – Alexander Mikhaylov May 30 '14 at 09:39
-
Sure. I just want to know the resoning, why? Anyone with insights? – powder366 May 30 '14 at 09:40
3 Answers
It is all about Flexibility: I assume you are familiar with so many Frameworks like for example e.g. Volley, Retrofit etc
. These Frameworks has their own Thread implementation behind scene so if Service
by default is executed in a separate Thread then it is overkill. Why? because the threading is handled by the framework already so why the need to have another thread?
See also Why is creating a Thread said to be expensive?. And put also into consideration that you are doing Threading in an Android device and not into a powerful Desktop.

- 7,365
- 6
- 33
- 39
Take a look at IntentService I think this is that you are looking for.

- 685
- 3
- 12
-
-
suppose you want to do some background work which is not going to consume too much of CPU time then rather than doing that work in a new thread,you can do it in main thread of your app(with less/no performance degradation). But if u were to something CPU intensive work then doing that in main thread of your application will slow down your application so for that you create a new thread and do the work in the new thread. – upenpat May 30 '14 at 09:48
It gives you more flexibility. For example you could run each request in a seperate thread with special priorities or you could store the requests in a queue and only start the next thread if the previous one has finished. A IntentService provides a default configuration that in the most cases fits your needs from scratch.(http://developer.android.com/guide/components/services.html). Such decisions depend on your use case.

- 2,144
- 2
- 13
- 13