Android Programming The Big Nerd Ranch Guide, 3rd Edition
For the More Curious: Alternatives to AsyncTask 497 For the More Curious: Alternatives to AsyncTask If you use an AsyncTask to l ...
Chapter 25 HTTP and Background Tasks 498 Challenge: Gson Deserializing JSON in Java objects, as you did in Listing 25.12, is a ...
499 26. Loopers, Handlers, and HandlerThread Now that you have downloaded and parsed JSON from Flickr, your next task is to down ...
Chapter 26 Loopers, Handlers, and HandlerThread 500 Next, update PhotoHolder to hold an ImageView instead of a TextView. Replac ...
Preparing RecyclerView to Display Images 501 Update PhotoAdapter’s onBindViewHolder(...) to set the placeholder image as the Ima ...
Chapter 26 Loopers, Handlers, and HandlerThread 502 Downloading Lots of Small Things Currently, PhotoGallery’s networking works ...
Communicating with the Main Thread 503 In Android, the inbox that threads use is called a message queue. A thread that works by ...
Chapter 26 Loopers, Handlers, and HandlerThread 504 Assembling a Background Thread Create a new class called ThumbnailDownloade ...
Assembling a Background Thread 505 Open PhotoGalleryFragment.java. Give PhotoGalleryFragment a ThumbnailDownloader member variab ...
Chapter 26 Loopers, Handlers, and HandlerThread 506 Finally, within PhotoAdapter.onBindViewHolder(...), call the thread’s queue ...
Handler anatomy 507 The target of a Message is an instance of Handler. You can think of the name Handler as being short for “mes ...
Chapter 26 Loopers, Handlers, and HandlerThread 508 Multiple Handlers can be attached to one Looper (Figure 26.5). This means t ...
Using handlers 509 Figure 26.6 shows the object relationships involved. Figure 26.6 Creating a Message and sending it In this c ...
Chapter 26 Loopers, Handlers, and HandlerThread 510 Next, add code to queueThumbnail(...) to update mRequestMap and to post a n ...
Using handlers 511 Finally, initialize mRequestHandler and define what that Handler will do when downloaded messages are pulled ...
Chapter 26 Loopers, Handlers, and HandlerThread 512 You implemented Handler.handleMessage(...) in your Handler subclass within ...
Passing handlers 513 You can also schedule work on the main thread from the background thread using a Handler attached to the ma ...
Chapter 26 Loopers, Handlers, and HandlerThread 514 In ThumbnailDownloader.java, add the mResponseHandler variable seen above t ...
Passing handlers 515 Next, modify PhotoGalleryFragment to pass a Handler attached to the main thread to ThumbnailDownloader. Als ...
Chapter 26 Loopers, Handlers, and HandlerThread 516 In ThumbnailDownloader.handleRequest(), add the following code. Listing 26. ...
«
22
23
24
25
26
27
28
29
30
31
»
Free download pdf