A small Android project to practice executing network requests and parsing the network response
This app uses the ZenQuotes API to generate an inspirational quote. Specifically, we will be using the https://zenquotes.io/api/random endpoint. Note that on a free account, you can only call the API 5 times every 30 seconds. Once you’ve reached that limit, you will no longer receive a valid response.
The app currently doesn’t work and requires a few fixes. This exercise takes you through the steps to produce a fully working app as pictured below.
- Clone this repo and import the project into Android Studio
- Launch the project on your Android device or emulator. Notice that the app is crashing on launch right now!
a) Fix the crash by looking at the logs to see what caused the crash. (Hint: There’s a TODO in ZenQuotesApiService)
b) See solution for fixing crash here
- Notice that unfortunately, there are still no quotes being displayed in the app. This is because the Quote class is currently incomplete. It should be parsing the JSON object for a Quote. The documentation for the response object is here: https://premium.zenquotes.io/zenquotes-documentation/#api-response. Use the documentation to complete the Quote class.
a) See how this is done in the Android Basics codelab on Step 8 for the @Json Annotation section
b) See solution here
- The last step is to set up an onClickListener for the button in the app to display a new quote.
a) See solution here
- Bonus step: Right now the app only displays the quote. But part of the response also includes the author of the quote. Display the author of the quote along with the quote itself!