Hi and welcome to the course. In this course, we are going to understand what exactly is a lifecycle-aware component. But to understand this with clarity, we will also explore what are lifecycles in Android, what are lifecycle observers, understand what are Event and States, who are called lifecycle owners?, importance and usage of LiveData, and last but not least how to write test case for lifecycle-aware components.
And we are going to understand all these topics using a demo application named AwarenessFood application. So before we start with the concepts, let’s take quick look at our demo application.
Open your Android Studio and import the starter project. Which you can get from the downloadable material of this episode.
While your project is getting built, go to spoonacular.com/food-api
. It’s basically a RESTful webservice for the food API which we will use in our project. So from here, I want you to create your account, it’s totally free. Signup and then login.
Within your API Console, go to profile, click this “Show / Hide API Key” and copy this API key.
Go back to your Android Studio, navigate to the di
package and open RecipesModule file. Here, replace this text with your API key. Like this!
Close the file and run your application.
You should be able to get a recipe on your screen - like this. So this screen is basically our MainActivity
.
If you click this refresh icon, then it will load another recipe from the API.
Next, from your menu if you go to ‘Food Trivia’ then this will open up FoodTriviaActivity
with FoodTriviaFragment
inside it.
Well, this fragment contains a button at the center, which at present does nothing. We will add functionality to this button as we proceed with the course.
Now, if you take a look at the project, it contain a few packages and classes which you should get acquainted with.
-
analytics
package contains classes for tracking application events. -
data
package contains model classes. -
di
package contains classes for providing dependency injection using HILT. -
monitor
contains classes for observing network connectivity. -
network
contains classes for accessing the external APIs using Retrofit. -
repositories
package contains classes for managing persistence. -
viewmodels
containsViewModel
classes which contains the business logic.
And then we have a small views
package which contains a custom View
.
And of course, down below within the main package we have our Activity
and Fragment
, even the Application
class in place.
So basically we are using a clean application architecture as recommended by Google. So yes, that’s all for this episode.