Android thread

Android modifies the user interface and handles input events from one single user interface thread. This thread is also called the main thread.

To provide a good user experience all potentially slow running operations in an Android application should run asynchronously

The Handler class can be used to register to a thread and provides a simple channel to send data to this thread.

To use a handler you have to subclass it and override the handleMessage() method to process messages.

Your thread can post messages via the sendMessage(Message) method or via thesendEmptyMessage() method to the Handler object.

Every app has its own special thread that runs UI objects such as View objects; this thread is called the UI thread. Only objects running on the UI thread have access to other objects on that thread. Because tasks that you run on a thread from a thread pool aren’trunning on your UI thread, they don’t have access to UI objects. To move data from a background thread to the UI thread, use a Handler that’s running on the UI thread.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s