On 08/08/2013 01:40 PM, ashish wrote:
I read about services in Android very carefully, but I didn't find any
valid reasons to use it. E.g.

 1.

    By default services run in the main thread, which most of the
    applications don't want.

 2.

    A service can run on a seperate thread if it spawns it own thread.
    But if a service runs on a seprate thread, then the method
    |stopService(new Intent(getApplicationContext(),
    MyService.class));| does not stop the running service. Again this is
    a problem.

If we want to do some background operations, then I think threads are
better than services. Am I right?

You've been already told by others that Services should be used to MANAGE separate thread(s).

The important part is that while an application is used to interact with the user a Service has no UI and can run in background.

And with "background" I don't necessary mean off-the-main-thread.
I mean that they can run even if the application (activities) is not used at the time.

Services have a simpler life cycle in respect to activities and they are not influenced or killed by the framework by changes in configurations.

Furthermore the framework will kill activities before starting to kill services. And if the framework decide to kill your service you can specify what you want to do with the request you received (drop it, ask the framework to re-do it, etc...)

Services are a main component of the system and it is good practice to, for example, use them to update underling data (better if using a SyncAdapter) and manage remote calls.

regards,
Daniele Segato

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to