(electronic music)
All right, so we've written the code now
to save the task details, let's see if it works.
We still haven't got the code to display the tasks yet,
but we're studying that in the next video.
But we can check the Logcat to make sure
our data has been saved.
If you wanna check the database,
which I'll be doing in a moment,
make sure you're not using
one of the emulators with Google Play.
They don't provide the permissions we need
in order to open the database on the device.
So what I'm going to do,
because I installed a Google Play version
of the emulator API 28,
I'm going to go ahead and create a new one.
Before I do that, though,
I'm going to edit the one we created.
I'll just change the name just to make it clear that
this is the Play version, Google Play version.
And I'm gonna create a new virtual device,
Nexus 5X again.
This time, we don't want the Google Play version.
I just gonna click x86 Images,
I'm gonna go for the Google API version,
or, of course, we can access the database,
and I'm gonna use API Level 28 again.
I'm gonna call this one API, just so it's clear to me
that we're using the Google API version.
All right, so now that we've got that created,
I'm going to just start it.
And I'll close down this Virtual Devices dialogue.
Now obviously, because this is a brand new emulator,
I won't open in the apps installed.
So if you've already created an emulator,
your probably want to uninstall the app from your emulator
to make sure there's no existing data in there,
because we're gonna run this version of the app
and enter some data as we go through.
But again, I just created an emulator,
so I won't need to test for that.
So I'm gonna make this a bit bigger.
This over to the right.
I'm gonna run this,
just by pressing Start.
All right, so I don't need to uninstall
the app from my emulator
to make sure there's no existing data,
and that's because you just saw me
create a new emulator.
If you're running an existing emulator,
then uninstall the app to remove all the data.
And in turn, what I'm going to be using here
for adding new data, which we want to test,
I'm gonna be really boring in my choice of tasks names,
but there's a good reason for it.
We'll see that is
when we come to respond to tabs
on the items a bit later.
For now, though, once the app's running,
make sure that Logcat's visible.
So I'm gonna go back and click on Logcat.
And notice that I'm still in floating mode
from the previous video,
so I'll leave that in that mode.
I have noticed, though,
that Logcat now behaves a bit differently
with this release of Android Studio.
Over in the filter box over here to the right,
it often resets to No Filters.
If I click this now,
the option to show any selected application,
which is the one we want here,
is also unavailable sometimes,
and you can see, at the moment, it's not showing.
It seems to be a bug, and if that happens,
use the second drop-down from left over here
to choose your application again,
and I think that it is actually chosen,
but I'll click on that again anyway.
And if I come back over here,
the option to show any selected application,
which is the one we want, is now there.
I can click on that, and we get to suggest our code.
And once, I'm gonna take the opportunity to remove
what we put in there before to the filter.
So we see everything for this app.
All right, so loading up our emulator again,
released, bring it back on screen.
Let's get started, so I'm gonna click on the plus,
the screen to add data screen appears, no surprises here,
and we call all the tasks Task with a number,
starting with the Task1.
Doesn't really matter what we use for the description,
so I'm just gonna enter first task, second task, and so on.
And next, what I'll do, also is, before I do that,
I'm gonna go back into Logcat,
and I'll just put Saving as a comment,
so we know where the log started.
All right, so let's start.
The first one, Task1.
Task description is gonna be first task,
and I'll leave the order or blank for that one.
Click on Save.
All right, and when I clicked Save,
you saw that the events were being logged.
And I go back over and have a look at that.
This is the first time
that we've accessed the content provider
after installing the app,
and we can see the table creation being logged there.
So that's followed by the insert method exiting
with the URI that it returns,
you can see that up there, you can just scroll over,
and we can see it's task slash one.
The URL contains an ID, so that's a good sign.
We wouldn't have an ID
if SQLite hadn't added the record to the database.
So let's go ahead and add another task now.
I'll call this one, not surprisingly, Task2,
second task for the description.
The sort order, this time, we'll add a sort order five,
and save.
If I scroll down, we can see that
we're still getting things updated, and we're confirming
that the data's been saved, that's good,
and we can just scroll over and see
we've got tasks, too, they're showing,
so that's a good sign so far.
Now, back to our app again.
There's another entry, this time, Task3,
description's gonna be third task,
and I'm going to enter the largest possible number
for the sort order, so that's nine nines.
One, two, three, four, five,
six, seven, eight, nine.
It won't let me top any more than that now,
actually, if I try anyway.
So that's also working fine.
I'll save that into the fourth task,
Task4, fourth task,
and I'll leave all the remaining sort orders blank.
So I'm gonna save that, back again to Task5,
fifth task, sort order blank as I mentioned,
and click on Save.
All right, that's enough records.
And we don't have to just trust
the Logcat entries here, by the way.
We can check the records using SQLite 3.
So to do that, we go back to,
actually, what I'll do is
I'll close down the Logcat for now.
Go back to open the Terminal.
I'm going to type adb devices.
I'm gonna type adb space dash s
space emulator dash whatever the number is,
in my case, 5554, shell.
Type su to switch into superuser mode.
And it's at this point that you might struggle
if you're using a real phone instead of an emulator.
And if that's the case,
you can't really check your database,
as you just have to trust the Logcat
until we display the records in the app
a little bit later, whereas our database
in the slash data slash data directory,
in a subdirectory that's the same name as our package.
So in my case, I can check with cd slash data
slash data slash, I can type in learn,
press Tab, that gives me the rest of the package name,
and then, I go into a subfolder
called databases, and press Enter.
And I can type sqlite3 TaskTimer,
capital T for Task, capital T for Timer, dot db.
And we'll select star from tasks.
And you can see that we've got our records showing.
So our code is adding your records
to the SQLite database, which is fantastic.
All right, so before I stop the video,
I'll close down the terminal
by typing exit to leave the SQLite show,
exit to quit superuser mode,
and exit once more to exit from id,
and exit to close down terminal.
All right, so in the next video,
we'll look at creating the adaptor what we'll need
to populate the recycler view
with the task records that we've saved.
See you in the next video.