O'Reilly logo

Java for Android, Second Edition by Budi Kurniawan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 45

Handling the Handler

One of the most interesting and useful types in the Android SDK is the Handler class. Most of the time, it is used to process messages and schedule a task to run at a future time.

This chapter explains what the class is good for and offers examples.

Overview

The android.os.Handler class is an exciting utility class that, among others, can be scheduled do execute a Runnable at a future time. Any task assigned to a Handler will run on the Handler’s thread. In turn, the Handler runs on the thread that created it, which in most cases would be the UI thread. As such, you should not schedule a long-running task with a Handler because it would make your application freeze. However, you can use a Handler to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required