O'Reilly logo

Pro Android 4 by Satya Komatineni, Dave MacLean

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

Using Worker Threads

When we use a handler like the one in the previous section, the code is still executed on the main thread. Each call to handleMessage() still should return within the time stipulations of the main thread (in other words, each message invocation should complete in less than five seconds to avoid Android Not Responding). If your goal is to extend that time of execution further, you will need to start a separate thread, keep the thread running until it finishes the work, and allow for that subthread to report back to the main activity, which is running on the main thread. This type of a subthread is often called a worker thread.

It is a no-brainer to start a separate thread while responding to a menu item. However, the clever ...

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