This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Data Persistence with Room!
You have completed Data Persistence with Room!
Preview
In this video we'll take a look at the app and see how it works!
Project Files
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now that we've got the app,
let's talk about what this app is.
0:00
Welcome to PizzaKeeper,
the only app that lets you create and
0:04
name your favorite pizzas.
0:08
In the main activity,
we'll show a list of created pizzas,
0:10
with the last item on the list being
the option to create a new pizza.
0:14
We don't have any pizzas yet.
0:18
But when an item on this list is clicked,
0:20
we'll start a new activity to
let users customize their pizza.
0:23
If they clicked an existing pizza,
we'll show that pizza.
0:27
And if they clicked the new pizza button,
they'll start with a blank canvas.
0:30
Right now, the app doesn't do very much.
0:35
We can change the name of the pizza And
0:38
click on toppings, But that's about it.
0:43
The save and
delete buttons just show toasts and
0:47
take us back to the main activity.
0:51
And if we rotate the screen, we can see
that our changes aren't being saved.
0:53
There's clearly some work to
do with data persistence.
0:58
But first,
let's take a look at the code and
1:02
get comfortable with how it all
comes together to create the app.
1:04
Starting from the top,
we have the data package.
1:11
This is where we'll be keeping all of
our files that have to do with data
1:15
persistance.
1:18
Right now, it just contains two classes.
1:20
One defining a Pizza object, and
one defining a Topping object.
1:23
Since our goal is to put this data
into the database, each of the objects
1:27
contains an id which can be used
to uniquely identify the object.
1:32
In addition to the id,
a Pizza will require a name and
1:39
the date it was created.
1:43
As for a Topping it will be
represented by an id, a name and
1:45
the name of the drawable we should
use to represent the topping.
1:50
Moving on the App file, at the top of
this file we define a topping's list,
1:55
which contains a toppings objects.
2:00
Remember, that in Kotlin, when a variable
is declared outside the scope of a class,
2:03
it's available from anywhere in the app.
2:08
So this toppings variable will be
available wherever we need it.
2:11
Above the toppings variable, we declare
a mapping of toppings to bBtmaps,
2:16
called toppingBitmaps.
2:21
When the application is first created,
2:24
we'll populate toppingBitmaps
with the Bitmap for each topping.
2:26
This way, instead of storing
entire Bitmaps in our database,
2:32
we'll just store the name
of the drawable and
2:37
turn it into a Bitmap when
the application is first created.
2:39
Also, just to be clear,
this application onCreate method will be
2:44
called before anything
happens with activities.
2:48
So by the time we're in main activity,
2:52
toppingBitmaps will be filled
with Toppings and Bitmaps.
2:55
All right,
that covers the first bit of code.
3:00
Coming up next,
we'll look at the rest of the code and
3:02
start planning how to
introduce data persistence.
3:05
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up