Service Vs Thread

by tarek.attia » Sun, 13 Jun 2010 21:46:55 GMT


Sponsored Links
 Hi all,

I have a question what to Use ,Service Or Thread,as both run in the
background

--



Service Vs Thread

by skink » Sun, 13 Jun 2010 22:47:39 GMT


 


no, services run in the UI thread

pskink

--


Sponsored Links


Service Vs Thread

by Kumar Bibek » Sun, 13 Jun 2010 22:52:24 GMT


 Services obviously don't run on the UI thread. It runs in the
background. However, Services have their own lifecycle, and can be
easily managed by applications. You can think of Services as an
extension of threads, in the sense that both of them do not run on the
UI thread.

Thanks and Regards,
Kumar Bibek






--



Service Vs Thread

by skink » Sun, 13 Jun 2010 23:21:59 GMT


 


only IntentService runs in its own thread.

ordinary Services run in the main (UI) thread of their hosting
processes:
  http://developer.android.com/intl/fr/reference/android/app/Service.html 

pskink

--



Service Vs Thread

by tarek attia » Mon, 14 Jun 2010 00:06:45 GMT


 Services Run in the background as stated here

*Services*A *service* doesn't have a visual user interface, but rather runs
in the background for an indefinite period of time
 http://developer.android.com/guide/topics/fundamentals.html 
So my question is when to use Services and When to Use threads ??...and Can
I make services inside threads??





>



Service Vs Thread

by Olivier Guilyardi » Mon, 14 Jun 2010 00:23:27 GMT


 


There is confusion here, because you are referring to two different meanings of
the word "background".

A thread, in Java but also in many other languages, allows for parallelization
within a single program/process, that is: doing several things at the same time.
If your program has a GUI and needs to do something heavy then you need to do it
in the "background" and thus within a separate thread, to avoid freezing the UI.
But this thread will terminate when your program terminates.

A service, in Android, is something which runs even when the application is not
in the foreground, that is: it continues to run when the user leaves your
activity and returns to home, or when the phone goes to sleep. If you don't need
this then you don't need a service.

As you may see, "background" here means something quite different, because a
service never runs in a dedicated /thread/. By default it runs in the main
application thread, and may optionally run in a separate /process/:
 http://developer.android.com/intl/fr/reference/android/app/Service.html 

--
  Olivier

--



Service Vs Thread

by Olivier Guilyardi » Mon, 14 Jun 2010 00:35:32 GMT


 




One thing that I forgot: if you need to have something to keep on running while
the user goes from one of your activities to the other, then you may also need a
service.

But the best would be that you explain what you are trying to do.


--
  Olivier

--



Service Vs Thread

by tarek attia » Mon, 14 Jun 2010 00:49:54 GMT


 Thanks you so much for this clarification ,,exactly I want to make an
application that keeps running while the user may went of the main
application ,,and I guess Service will be the best candidate for doing
that  ,,,,,,,

But what if the application will take much time ,,so should I make a thread
that embedded inside it a Service??








>



Service Vs Thread

by Frank Weiss » Mon, 14 Jun 2010 01:03:51 GMT


 The problem appears to mainly be the formulation of the question. In
Android, an application doesn't run - it's just a collection of
resources. Of those resources, Activities and Services can run, but
their runtimes are relatively brief. Please try to explain what your
application needs to do when it has no visible Activity. The
recommended solution would depend on that.

--



Service Vs Thread

by Olivier Guilyardi » Mon, 14 Jun 2010 06:01:11 GMT


 


Yes, exactly. If you need to do something heavy in the service, it must happen
in a dedicated thread, otherwise you will freeze the application main thread
(and thus the UI) which you should never do.

So, you might need both a service *and* a thread.

--
  Olivier


--



Service Vs Thread

by Olivier Guilyardi » Mon, 14 Jun 2010 06:09:45 GMT


 




Little clarification: of course this thread must be "embedded" in the service,
not the opposite. The service acts as an entry point, in which you can create
several threads if you like.

--
  Olivier

--



Service Vs Thread

by tarek attia » Mon, 14 Jun 2010 21:55:18 GMT


 Thank you so much for such help ,,,,

Again all my application requires the following :-


   1. The application should be able to run in the background when other
   applications are running in the foreground.
   2. When the application is on the foreground, it should shows certain
   stuff to the user

So Service is the best candidate for that ??








>



Service Vs Thread

by Kostya Vasilyev » Mon, 14 Jun 2010 22:27:32 GMT


 Yes, this is exactly what services are for.

Services are a way to tell Android that certain code in your application 
is important to the user, and Android should make an effort to keep it 
running even when it doesn't have active activities.


For user notifications, take a look at NotificationManager and its 
related class, Notification.


-- Kosyta

14.06.2010 17:54, tarek attia ?????:
Thank you so much for such help ,,,, Again all my application requires the following :- 1. The application should be able to run in the background when other applications are running in the foreground. 2. When the application is on the foreground, it should shows certain stuff to the user So Service is the best candidate for that ?? On Mon, Jun 14, 2010 at 1:09 AM, Olivier Guilyardi <l...@samalyse.com >> Thanks you so much for this clarification ,,exactly I want to make an >> application that keeps running while the user may went of the main >> application ,,and I guess Service will be the best candidate for doing >> that ,,,,,,, >> >> But what if the application will take much time ,,so should I make a >> thread that embedded inside it a Service?? > > Yes, exactly. If you need to do something heavy in the service, it must happen > in a dedicated thread, otherwise you will freeze the application main thread > (and thus the UI) which you should never do. > > So, you might need both a service *and* a thread. Little clarification: of course this thread must be "embedded" in the service, not the opposite. The service acts as an entry point, in which you can create several threads if you like. -- Olivier --



Service Vs Thread

by schwiz » Mon, 14 Jun 2010 22:41:54 GMT


 your service will want to spawn its own thread or asynctask to do your
heavy work or else you will get a forceclose.




--



Other Threads

1. How to narrow down the method that is involved in exception from the pid

> Ljava/lang/IllegalStateException;: Finalizing cursor

This is a strange one. I find that this error is given in two
situations
1/ When I forgot to close a cursor.
2/ When I dumbly tried to reuse a cursor without first closing the old
instance.

That is I forgot to close a cursor.

The two hints you have to finding the cursor are
1/ the table name - which mysteriously in your case is null, and
2/ the object address

I'd look for a query that has "null" where the table name should be.

and

If you have some idea as to roughly where this is,and not to many
cursors, splash a few..

Log.i(TAG, myCursorHere.toString())

after your queries to get the address for each cursor you created.



> 

2. In process communication

Hi @all,

I have a design problem with my Android components.

My activity is starting a service which is doing the work in the
background. What I want is that the service informs the activity about
state changes. How can I do this?

Normally I would add an observer but the activity has no reference to
the service. Then I was thinking to take AIDL but this is more for
inter-process communication.

How is it possible that the service informs the activity about state
changes? Both are running in the same process. What can you recommend?

Thank you in advance.

T-Droid

-- 

3. Android monkey tool script

4. Media gathering and launching HTC Legend, HD Mini dan HTC Smart

5. Bluetooth error

6. Parcelable datatype in AIDL file

7. Adding an HTML content to a webview without space