Welcome back and this video, we are going to solve an issue that we still have and we're also going
to prepare the activity that we are going to need for the next video.
So one thing that we currently have is once we add a new entry here.
So I'm going to call this one test five.
And I'm going to add an image here to select one from the gallery.
Let's use humor here once again.
Let's save this, we go back and see the place was at it, but it's not in this list, so this green
is not being notified about that and that is something that we still need to implement.
So let's fix that first and then we are going to add the activity that will open up later on once we
click one of those elements here.
All right.
So let's go ahead and do that.
So the first thing we need to do now start an activity for result, because currently what we do is
we only start in activity, but we actually want to have a result here.
So I'm going to add four result.
And if you do that, then you need to pass an integer.
So we need to add something else here.
And I'm going to call this integer add underscore place on this core activity request code.
All right.
And this will be.
Another static variable that I need, so I need to have a companion object here.
Companion object.
And I'm going to create this variable here, which I'm going to assign the world you want to so far
at your request, code one.
Now we can go ahead and go to our ad Happy Place activity.
And here inside of our button, click so on button safe.
We check if happy place or if I'd place Krater zero at that point, currently we just display.
A toast where we say a happy place.
Details are inserted successfully, so instead of doing that, I want to set the result, so I'm just
going to say activity.
The result is OK.
Because now.
Our main activity since the activity for results, so it starts out here, start activity for resolve
and it sends the number here, which is our ad happy place activity request code.
And then in our ad heavy place activity there, at the point where we save it, we can say, OK, the
result is that it's OK.
So now we can go ahead back to our main activity and implement our own activity result.
So here are right on activity result.
And what I want to do here is I want to check if the request code that we sent was this one here, our
had place activity request code.
So if request code is equal to.
Had police activity request code.
Then I want to check if the result code is equal to activity dot result.
OK.
And then I want to call my get happy place from database or from local database, so this is this.
Function that we created here, which gives us all of the happy places, right, and we, so to speak,
refresh it here.
Right.
And otherwise I can just write a log here, log e activity.
And the message will be canceled.
Or back pressed.
Because of the user prospect, for example, then he didn't create a new entry, so we don't need to
call this get happy place this list from local database, which will then.
Refresh everything, as you can see, so it gets everything and then it sets everything up, so especially
this set up, happy place, recycled view, which sets up the result of you with the latest data.
That's where we are currently lacking.
All right, now we can test this again, all right, so that we are you can see test five now is there?
But that's not what we wanted to test.
We want to see if test six is going to be there.
And I'm going to add an image here from gallery again, because it's quicker, so let's take this image.
It's safe and we can see it's there directly.
All right, perfect.
So that is exactly what we wanted, because maybe you were testing your application before and you realized,
oh, man, it's updating the list.
So something must have gone wrong.
But that's just because we haven't implemented the feature yet and now you know how to implement it
and why it's important to do so.
This could have been a super short video, but I think it makes sense to add something else for the
next video in preparation, because what we are going to require is a new activity.
That will open up once we click on any of those elements here.
All right, so let's prepared let's create a new activity here.
New activity is an empty activity here.
And I'm going to call this one happy.
Place detail activity for now, the only two things that I'm going to do is I'm going to go to the manifest
and set that activity up, that it looks the same as our others, which means it has the same theme
and it has the same orientation.
So here for this activity here.
Go to had the code here.
And that one will be called a little different.
So here it will be a happy place.
Details.
And later on, we can change that label.
And then we need to import our here because our R is in a different bundle or in a different directory,
so we need to import that real quick and our happy place detail activity.
And then the final thing that I want to do for this video is to add something to the layout, which
will just be the bar at the top.
So here.
Had a happy place.
Let's go to the code and here we are, the toolbar, so I'm just going to copy this toolbar here because
I want to use the same toolbar in my.
Happy place detail activity here.
And I'm going to call this one.
Heavy police detail.
All right, so we're not going to be able to see that yet, but we're going to add that in the next
video.
So see you there.