tags:

views:

106

answers:

1
+4  Q: 

Handler vs Thread

Hi, I would like to know, once for all.. ive read in many places.. when i wanna do some 'long time operations' i should use a Handler.

But i dont get why? all my 'long-time-operations' i surround with a regular threads, and it works fine.

why would I use handler for this?

the only time i had to use Handler was, when I had to scheduale some task(postDelayed)

Is there any main idea i miss about handlers(When i should realy use it)? or mybe there isnt realy diffrence?

realy thanks,

ray.

+7  A: 

A Handler lets you communicate back with the UI thread from your background thread. This is because UI operations are forbidden from within background threads. Note that starting at version 1.5, the AsyncTask class makes it much easier to do so.

JRL
So in other words, only when i wanna communicate my background thread with the UI, I should use Handler?
rayman
@rayman: if you need access to any UI component, you need a Handler - but if you're targeting API level 3 and above, AsyncTask makes the job easier for you. If you don't need access to the UI at all you don't need either and can just spawn a new Thread.
JRL
Gotcha! thanks.
rayman