Welcome to Unit 4 of Android Basics.
You're now over halfway done with this course, so congratulations!
Previously, you learned about the Jetpack navigation
and architecture components.
You worked on four different apps
applying new skills you learned throughout the course.
Now you can build apps where your users can navigate
through multiple screens of your app with ease.
Now, this unit is focused on helping you build apps
that can get data from the internet.
This is a big step in your Android development journey.
The apps you've built so far displayed information
that was already built into the app, like a words list.
But sometimes, you can't include all that information upfront in the app.
Sometimes, the latest up-to-date data needs to come
from a source that's outside of your phone.
It needs to come from something we call a server.
You can think of a server as a computer or a group of computers
that can take certain types of requests and provide appropriate responses.
Many of the apps that you use on your phone connect to a web server.
For example, the weather app on your phone gets data
from a weather server and displays it on this screen.
The news app gets articles and headlines from a news server and so on.
Being able to download data, both text and images
onto the phone will allow you to have a richer and more useful experience
for the users of your app.
To learn these new concepts
you're going to be building the Mars Photos app.
It displays a grid of different photos of the planet Mars.
The grid is implemented as a RecyclerView
which you're already familiar with
and you'll be building this app in two stages
by making use of some third-party libraries
called Retrofit and Coil.
Remember that a library is a grouping of code
that helps developers achieve a certain purpose.
In the first stage of building the Mars Photos app
you will make a request to a web server with the Retrofit library
to get the list of all the Mars image URLs.
This is all text data.
The image URLs are not the images themselves
but the addresses where we can retrieve the images from.
In the second stage, you will use the Coil library
to actually load the images.
For each URL, you will make a request to download the image
and load it into the appropriate image view
on the screen.
Before we dive into the Mars app though
we'll talk about an important part of programming, which is concurrency.
You can imagine that something like having the app get data from a server
would be a non-trivial task and could take some time to accomplish.
The time duration can depend on factors like how fast the internet speed is
or the size of the data that we want to download.
So if this process ends up taking a long time
we don't want our app to freeze
or just sit around waiting for the results.
Our Android devices are powerful
and can do multiple things at once concurrently.
So we can still be responsive to the user while we are waiting
for the result from the server in the background.
Work can be split up into threads.
The main thread is responsible for displaying the UI
and responding to the user
if they click a button or scroll the screen.
Meanwhile, we can have a background thread
that is doing time-consuming work like making a request for the Mars data.
Coordinating between these two threads can be tricky.
But luckily, Kotlin offers Coroutines as an easy way
to perform background work in your app
and to write the code in a way that reduces the risk for errors.
So you'll first learn about Coroutines in the Kotlin Playground
before applying it within the context of the Mars Photos app.
There's a lot to cover, and there will be some challenging new concepts ahead
but we're confident that you're ready for this.
After this unit, you'll have the skills you need
to get data from a web service into your own app
which unlocks a whole world of possibilities.
So let's get started and see what Mars looks like.