Exercise – using coroutines in an Android app
In this exercise, you will be working with an application that displays movies that are playing now in cinemas. You will be using The Movie Database API version 3 to get the list of movies. Go to https://developers.themoviedb.org/3 and register for an API key. Once you’ve done that, follow these steps:
- Open the
Movie Appproject in theChapter02directory in this book’s code repository. - Open
MovieRepositoryand updateapiKeywith the value from The Movie Database API:private val apiKey = "your_api_key_here"
- Open the
app/build.gradlefile and add a dependency forkotlinx-coroutines-android:implementation ‘org.jetbrains.kotlinx:kotlinx- coroutines-android:1.6.0’
This will add the kotlinx-coroutines-core and kotlinx-coroutines-android libraries to your project, allowing you to use coroutines in your code.
- Also, add the dependencies for the
ViewModelextension...