Home > Android Development > Android Handler object

Android Handler object

A useful object to know, is Android’s Handler object.
Why should we use it? or more correctly when should we use it?
Well, in many programming language, maybe even all of them, we can’t update a UI component from a different thread.
UI components can only be updated from within the main UI thread, and Android is no exception.

Using the Handler object is very simple:

1. Create the handler object at the main thread (UI Thread).
2. Pass it to the secondary thread.
3. Secondary thread can now use the Handler’s post method and supply a Runnable for it, enabling to do what ever UI updating you want to do.

Simple as that, but vary important tool to use!

Categories: Android Development
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: