Does service launched from its activity runs in a new Thread?
Launching a service for first time from its activity like
this.startService(new Intent(this,UpdaterService.class));
does this service runs in a new thread ? And if I put heavy work load on this service (without taking开发者_StackOverflow help of thread) will android will show force close for this application ??
And how different is AsyncTask class from Thread class ?? which one to use where ?
Thanks.
Android developer manual reads:
- A
Service
is not a separate process. TheService
object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of. - A
Service
is not a thread. It is not a means itself to do work off of the main thread (to avoidApplication
Not Responding errors).
Service is running in a different process, it's just an application without a user interface. AsyncTask is just a helper class that helps you do some work on a separate thread and synchronize it with your UI thread, for example to show current progress to your users. You can use AsyncTask when you need this type of synchronization, but generally there is no big difference between using any of these. Hope this helps.
精彩评论