24
HTTP and Background Tasks

The apps that dominate the brains of users are networked apps. Those people fiddling with their phones instead of talking to each other at dinner? They are maniacally checking their newsfeeds, responding to text messages, or playing networked games.

To get started with networking in Android, you are going to create a new app called PhotoGallery. PhotoGallery is a client for the photo-sharing site Flickr. It will fetch and display the most interesting public photos of the day according to Flickr. Figure 24.1 gives you an idea of what the app will look like.

Figure 24.1  Complete PhotoGallery

Complete PhotoGallery

(We have added a filter to our PhotoGallery implementation to show only photos listed on Flickr as having no known copyright restrictions. Visit flickr.com/​commons/​usage/ to learn more about unrestricted images. All other photos on Flickr are the property of the person who posted them and are subject to usage restrictions depending on the license specified by the owner. To read more about permissions for using images that you retrieve from Flickr, visit flickr.com/​creativecommons/.)

You will spend several chapters with PhotoGallery. In this chapter, you will learn how to use the Retrofit library to make web requests to REST APIs and the Gson library to deserialize the response to these requests from JSON into Kotlin objects. Almost all day-to-day programming of web services these days is based on the HTTP networking protocol. Retrofit provides a type-safe way to access HTTP and HTTP/2 web services easily from Android apps.

By the end of the chapter, you will be fetching, parsing, and displaying photo titles from Flickr (Figure 24.2). Retrieving and displaying photos will happen in Chapter 25.

Figure 24.2  PhotoGallery at the end of the chapter

PhotoGallery at the end of the chapter
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.198.129