Welcome back.
Our app is missing a very important feature, and that is to display the information that should be
displayed here once we click on one of the elements.
So how do we get the information from one screen to another?
Well, one of the options is, of course, to use put extra to an intent, and that's exactly what we're
going to do.
So let's go ahead and go to our main activity and end our setup happy place recycler view function that
we had this set list for our places adapter and there we had this unclick, which we implemented last
video.
Now, before I start the activity, I would like to put something in the Internet.
So I would like to put some extra information to the intent.
And I'm going to call this one extra place details.
And what I'm going to pass is the model.
All right.
So this extra put extra method, as you can see, it requires a string, which is the identifier, so
to speak, and then a bunch of different other types of information that you can pass.
It can pass integers, you can pass doubles and so forth.
So you could pass any different type of information.
But the thing is, what I want to pass is a whole object.
All right.
So let's create this variable real quick in our companion object here for is going to be extra place
details.
So it will be identifiable, so the extra information that we're putting, because we could put a lot
of different information.
OK, but now it's still complaining and that is because it doesn't understand what it should do with
our model, because our model is an object of a class that we created ourselves and put extra requires.
You could see data types that it can read.
So, for example, something that a serializable, that's exactly what we're going to use.
So let's go ahead and make our model or our class serializable.
So let's go to our Happy Place model and make this data class.
Syria sliceable that will allow us to do is it allows us to pass it to our intent.
So basically what Serializable does is serializable will bring it into a format which we can pass from
one class to another.
All right.
So that is simply very powerful.
It's also used in order to save an object.
OK, so if you want to store an object of a class, then you can store it in a serializable way as well.
But that is a little different of a topic.
But basically that is how we can pass the information.
But now, of course, that is just one step of it because we also need to retrieve it.
So let's retrieve it.
And where would that be?
Well, in our happy place detail activity, because that's where we are going to need it.
So let's go ahead and.
Create an object of our happy place model, so far, a happy place detail model will be our happy place
model Nullable and then we check if the Internet has information, so has extra.
Called main activity, that extra place detail, we called it like that, as you can see in our main
activity, this is our companion object variable, this static variable that we have here that we now
can use and can see if it has this specific name, then do something with it.
So we're saying, OK, does it have an extra which has this name?
And if it does, then run some code and that's what we're doing here.
So we're saying assign the intense get a serializable extra main activity that.
Extra heavy police detail as a happy place model, because it's not going to be in the form of a happy
place model, so we want to cast it to be one.
All right.
So now it's going to be one.
So now that we have assigned it, we can check is our happy place model or detail model not empty,
so happy place model, not now.
Then.
We want to have an actual bar at the top, so I'm just going to use the tool bar, Happy Place Detail
Action Bar.
Then I'm going to say that it is going to be or it's going to have this back button, so support action
bar.
Set display home as unable to I'm going to say that's true.
And then I'm going to set its title.
So Support Action Bar, the title is going to be a happy place model the title.
So whatever we had as the title in our happy place model.
So the string here, that's going to be the title of our action bar.
So instead of just having a happy place detail, as we currently have called it.
So here.
Our.
Very top here hour toolbar, the current text is.
We even have a text here.
Actually, we don't have a text here, so now it's going to get a text, which is going to be the title
of the Happy Place detail model.
And then what should happen once we click on this thing?
Well, then we want to set it as back pressed.
OK, so once we click on our navigation element here, set navigation, I'll click listener on back
pressed should be called OK.
And at this point we can go ahead.
And assign all of the different.
Details here, so all of the different information, such as which image to use, which text to use
and so forth, because we have here a complete image of you, which is Ivy Place image.
This is the one that we want to populate with the image of the element that we clicked on.
So here, if we click on this one, we want to have Holmer.
So here, this image here should be Homerton.
All right, so let's assign it let's go ahead and say on the score place image, that set image.
So how did we store it?
Well, we store the image as a string, which means we store it as a link.
So we started as a you are I, so to speak.
So set image, you are right.
Which will be your parts, because now we need to bring it back into a URAI format and that will be
our happy place detail model.
Dot image.
And of course, we need to import Urai, so let's do that real quick here, import this and now we can
go ahead and set the same for our text here, of course.
So what was the name of our description text here?
I think TV description.
So let's look at it yet.
It was TV description, so let's use that.
So let's set its text to Happy Place model is a model to be precise and description.
And then TV underscore what we have OK with location.
Text is going to be our happy place detail model location.
All right, so now we can test that and see if it's actually going to work.
And then while it's running, I want to also talk about a little other aspect of using our serializable.
So serializable is one way, but there is another option for this.
And we're going to look at that in a second.
So first of all, let's test it, let's click on Holmer and we could see the Holmer image is populated.
The test description and test location are the text here.
So that worked flawlessly.
Perfect.
All right, and it's quick enough, right?
But then when developing this, I came across Pasodoble versus Serializable, and that is something
that you always can do, you can always improve your coding or your performance of your app.
And of course, at one point, it doesn't really matter that much because in our case, I mean, the
application is fast enough, right?
So it's super fast even in the emulator, which is a super slow device.
But still, if you look at it, there is an alternative to serializable, which is called personable.
And you can check out this article here.
But basically what he says is that using Soheir Pasodoble versus serializable and he says that using
pasodoble is going to be significantly faster than using serializable.
So it is like 10 times faster.
All right.
So let's try that.
So how we do we make this happy place model Pasodoble?
Well, you can just use Parcell Bolt here the keyword, and then it's going to complain, it's going
to say, OK, you need to implement pasodoble methods and stuff.
So let's let's add this implementation.
You can see and add this constructor, but then it's complaining because strings need to be nullable
for this to work.
So let's add a bunch of question marks here for our strings so that it's not complaining anymore.
All right.
So once we've done that, the next thing we need to do is, of course, to go to our main activity where
we passed in this detail and we started this.
Intent, let's have a look can see.
OK, so we put it Ekstrom and our put extra, it doesn't care if it's a pasodoble or if it's a as you
can see in this case, it directly shows us the pasodoble option.
But there is also one, which, of course, is the serializable that we used before.
But now it's automatically going to use to pass the little option.
And then the next thing we need to do is to check out the happy place, detail activity, because here
we used to intend to get serializable of extra.
So now I'm just going to use get Pasodoble Extra.
And that's going to be it.
So that's just another way of using objects that you want to pass around between different activities
so you can use whatever way you prefer.
I mean, serializable was the easier one, so to speak, but it's the less performant one.
So if you really want to improve the performance of your application, then you can use Pasodoble here.
And then, of course, when you do these changes, it's important to test if it's still going to work.
And as you can see, it still seems to work totally fine.
All right, so that was it for this video.
Now you know how you can pass around the whole objects from one activity to another and you can use
it there in order to populate, for example, your UI.
And that will be super handy because you will need that functionality quite often.
All right.
So see you in the next video.