Assembling a Background Thread

Create a new class called ThumbnailDownloader that extends HandlerThread. Then give it a constructor, a stub implementation of a method called queueThumbnail(), and an override of the quit() method that signals when your thread has quit. (Toward the end of the chapter, you will need this bit of information.)

Listing 26.4  Initial thread code (ThumbnailDownloader.java)

public class ThumbnailDownloader<T> extends HandlerThread {
    private static final String TAG = "ThumbnailDownloader";

    private boolean mHasQuit = false;

    public ThumbnailDownloader() {
        super(TAG);
    }

    @Override
    public boolean quit() {
        mHasQuit = true;
        return super.quit();
    }

    public void queueThumbnail(T target, String url) {
        Log.i(TAG, "Got ...

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.