A thread certainly does not depend on Activity.

Java Threads do not "die" or do anything else when an activity is closed, because they have no knowledge of activities and have nothing to do with Android (as should be apparent by the package name: Thread is defined in java.lang).

A service does not necessarily use threads, either. By default, a Service's callbacks are executed on the UI thread, just like Activity callbacks or BroadcastReceiver callbacks. Not every service is an IntentService (which does use threads) or creates threads in some other way.

And that's really the difference: a Service is a thing that Android is aware of, which can be used to various ends.

A service can be started or bound by other components, and/or given a foreground priority, which affect the process's lifetime, can be communicated with using Intents or AIDL, possibly by other applications. Last but not least, a service is visible to the user via the Settings app. None of this applies to a Java Thread.

On the other hand, plain Threads have their use too, where none of the above is needed or desired.

-- Kostya

11.04.2011 18:24, luiX_ ?????:
well... I'll say "very little" in common, but that's true: you cannot do the same with a service and an extra thread as the thread depends on the main Activity and it "dies" when the Activity does :P

2011/4/11 Mark Murphy <[email protected] <mailto:[email protected]>>

    On Mon, Apr 11, 2011 at 5:54 AM, Tushar Baviskar
    <[email protected] <mailto:[email protected]>> wrote:
    > What is the need of services in android, as same thing can be
    achieved
    > by starting new task also?

    No, the "same thing" (whatever that is) cannot "be achieved by
    starting new task also". Services and tasks have virtually nothing in
    common and certainly are not interchangeable.

    http://developer.android.com/guide/topics/fundamentals/services.html

    --
    Mark Murphy (a Commons Guy)
    http://commonsware.com | http://github.com/commonsguy
    http://commonsware.com/blog | http://twitter.com/commonsguy

    _The Busy Coder's Guide to Android Development_ Version 3.6 Available!

    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:android-developers%[email protected]>
    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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to