O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

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

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 (ThumbnailDownloader.java)

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​(​)​ ...

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