O'Reilly logo

Asynchronous Android by Steve Liles

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

Applications of Handler and HandlerThread

The Handler class is incredibly versatile, which makes its range of applications very broad.

So far we looked at Handler and HandlerThread in the context of the Activity lifecycle, which constrains the sort of applications that make sense—ideally we do not want to perform long-running operations (more than a second or so) at all in this context.

With that constraint in mind, good candidate uses include performing calculations, string processing, reading and writing small files on the filesystem, and reading or writing to local databases using a background HandlerThread.

We might consider AsyncTask instead for one-off's, or if we want to display progress or cancel a task part way through. The Android platform ...

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