Assembling a Background Thread

Create a new class called ThumbnailDownloader that extends HandlerThread. Your ThumbnailDownloader’s user will need to use some object to identify each download, so give it one generic argument called Token by naming it ThumbnailDownloader<Token> in the class creation dialog. Then give it a constructor and a stub implementation of a method called queueThumbnail() (Listing 27.2).

Listing 27.2  Initial thread code (

p​u​b​l​i​c​ ​c​l​a​s​s​ ​T​h​u​m​b​n​a​i​l​D​o​w​n​l​o​a​d​e​r​<​T​o​k​e​n​>​ ​e​x​t​e​n​d​s​ ​H​a​n​d​l​e​r​T​h​r​e​a​d​ ​{​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​s​t​a​t​i​c​ ​f​i​n​a​l​ ​S​t​r​i​n​g​ ​T​A​G​ ​=​ ​"​T​h​u​m​b​n​a​i​l​D​o​w​n​l​o​a​d​e​r​"​;​

 ​ ​ ​ ​p​u​b​l​i​c​ ​T​h​u​m​b​n​a​i​l​D​o​w​n​l​o​a​d​e​r​(​)​ ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.