There is a major difference between a Thread
and a Handler
.
The Android Handler
class is used for communication between other Runnable
/Thread
and the one that it has been created in.
By posting to a given Handler
, you can add something for execution on its thread.
You can also send messages from one thread and handle them on another.
Using Handler
, for example, is the preferred way to do delayed execution, instead of using TimerTask
. You can also notify your main thread that your worker thread has finished some task, with Handler
as an alternative of sending Intent
.
From Android Developer's site:
There are two main uses for a Handler:
(1) to schedule messages and runnables
to be executed as some point in the
future; and (2) to enqueue an action
to be performed on a different thread
than your own.