Mr Coder
Mr Coder

Reputation: 8186

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 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.

Upvotes: 1

Views: 413

Answers (2)

Barmaley
Barmaley

Reputation: 16363

Android developer manual reads:

  • A Service is not a separate process. The Service 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 avoid Application Not Responding errors).

Upvotes: 2

Egor
Egor

Reputation: 40203

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.

Upvotes: 1

Related Questions