What is the different b/w running runnable inside handler new Handler().post(runnable) and running in Thread(runable) ?
A:
Handler.post()
has the Runnable
execute on the main application thread. new Thread()
creates a new thread.
CommonsWare
2010-02-02 12:01:46
Well, no, `Handler.post()` has the `Runnable` execute on the thread in which the `Handler` was created. That doesn't necessarily mean it's the UI thread.
Matthias
2010-02-02 12:11:19
+5
A:
Handler
is used for communication between and coordinating threads. By creating a Handler, you bind it to the current thread. If you post a runnable to that Handler, it will be executed in that same thread.
Thread
is Java's way to spawn new user-level threads. The runnable you pass it will be executed in that thread.
The two concepts are not mutually exclusive. You can use Handler
with custom Thread
s.
Matthias
2010-02-02 12:15:35