The intention of this workshop is to learn about background processing in Android, and how to request data from external APIs.
- Using AsyncTask for background work in Activities.
- Retrieve network data with OkHttp.
- Request data to a REST API using Retrofit.
- Store local data in SharedPreferences.
In this workshop we're not building a new project from scratch, but rather using a base project with a couple of activities and evolve it integrating the features above.
We're building an application that lists Super Heroes retrieved from the Marvel API. Our base project has two Activities:
- Super Heroes list (MainActivity): A list of images and names of the available super heroes.
- Super Hero Detail (SuperHeroDetailActivity): A detailed view of a single Super Hero, with bigger image, name and description.
The Super Heroes are retrieved from each Activity through a SuperHeroesRepository. In the base project this repository is implemented with fake data and a Thread.sleep() to simulate network delay.
MainActivity | SuperHeroDetailActivity |
---|---|
Here! 😃
Every commit in the repo is an small individual step. You can check out the list of commits to view the detailed process step by step.
- Base project: A two activity application which shows a list of super heroes and their detail | e2d76bb8
- Creating AsyncTasks for retrieving super heroes in background | 5738c511…31abbbb4
- Requesting data from a real API using OkHttp | dbb39f56
- Implementing the API with Retrofit 1.9 | 4e657c0a
- Storing and reading favorite super heroes with SharedPreferences | 73789d9e…44c98781
The app's look and feel are based on Karumi's SuperHeroes kata. If you're interested in testing, check it out!