Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

6.4. Summary

In this chapter, we showed you how to keep your applications responsive by doing expensive work in separate threads. We started simple, with Java’s basic concurrency facilities like the Thread class and moved ahead to show you how to let a worker thread update the user interface using Android’s message passing duo Handler and Message. We also beefed up MyMovies to asynchronously download movie thumbnails, as an example of how to manage multiple download threads in a resource sensitive way using Java’s thread pools and executors.

Though this gave us a lot of flexibility, job classes are often cookie-cutter classes and contain a lot of boilerplate code, which we removed by simplifying worker thread scenarios using Android’s AsyncTask class. We wrapped up the chapter by learning how scheduled delayed jobs can be used to implement splash screens, and how to create custom message loops to communicate freely between any number of threads, without using a single object lock or other synchronization primitives. What a ride!


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial