1
00:00:00,470 --> 00:00:01,330
Welcome back.

2
00:00:01,650 --> 00:00:08,430
Our app is missing a very important feature, and that is to display the information that should be

3
00:00:08,430 --> 00:00:10,980
displayed here once we click on one of the elements.

4
00:00:11,280 --> 00:00:14,550
So how do we get the information from one screen to another?

5
00:00:15,120 --> 00:00:20,580
Well, one of the options is, of course, to use put extra to an intent, and that's exactly what we're

6
00:00:20,580 --> 00:00:21,060
going to do.

7
00:00:21,330 --> 00:00:30,330
So let's go ahead and go to our main activity and end our setup happy place recycler view function that

8
00:00:30,330 --> 00:00:36,990
we had this set list for our places adapter and there we had this unclick, which we implemented last

9
00:00:36,990 --> 00:00:37,410
video.

10
00:00:37,740 --> 00:00:44,670
Now, before I start the activity, I would like to put something in the Internet.

11
00:00:44,850 --> 00:00:48,480
So I would like to put some extra information to the intent.

12
00:00:48,960 --> 00:00:54,510
And I'm going to call this one extra place details.

13
00:00:55,170 --> 00:00:57,690
And what I'm going to pass is the model.

14
00:00:59,010 --> 00:00:59,430
All right.

15
00:00:59,440 --> 00:01:05,280
So this extra put extra method, as you can see, it requires a string, which is the identifier, so

16
00:01:05,280 --> 00:01:09,710
to speak, and then a bunch of different other types of information that you can pass.

17
00:01:09,720 --> 00:01:12,810
It can pass integers, you can pass doubles and so forth.

18
00:01:12,810 --> 00:01:15,980
So you could pass any different type of information.

19
00:01:15,990 --> 00:01:19,140
But the thing is, what I want to pass is a whole object.

20
00:01:19,860 --> 00:01:20,210
All right.

21
00:01:20,220 --> 00:01:31,050
So let's create this variable real quick in our companion object here for is going to be extra place

22
00:01:31,050 --> 00:01:31,770
details.

23
00:01:33,500 --> 00:01:40,010
So it will be identifiable, so the extra information that we're putting, because we could put a lot

24
00:01:40,010 --> 00:01:41,120
of different information.

25
00:01:41,320 --> 00:01:46,820
OK, but now it's still complaining and that is because it doesn't understand what it should do with

26
00:01:46,820 --> 00:01:55,270
our model, because our model is an object of a class that we created ourselves and put extra requires.

27
00:01:56,060 --> 00:01:58,260
You could see data types that it can read.

28
00:01:58,700 --> 00:02:03,300
So, for example, something that a serializable, that's exactly what we're going to use.

29
00:02:03,800 --> 00:02:08,720
So let's go ahead and make our model or our class serializable.

30
00:02:08,750 --> 00:02:13,040
So let's go to our Happy Place model and make this data class.

31
00:02:14,090 --> 00:02:22,730
Syria sliceable that will allow us to do is it allows us to pass it to our intent.

32
00:02:23,330 --> 00:02:30,260
So basically what Serializable does is serializable will bring it into a format which we can pass from

33
00:02:30,260 --> 00:02:31,370
one class to another.

34
00:02:32,060 --> 00:02:32,450
All right.

35
00:02:32,450 --> 00:02:34,940
So that is simply very powerful.

36
00:02:34,970 --> 00:02:38,780
It's also used in order to save an object.

37
00:02:39,070 --> 00:02:46,040
OK, so if you want to store an object of a class, then you can store it in a serializable way as well.

38
00:02:46,200 --> 00:02:48,560
But that is a little different of a topic.

39
00:02:48,710 --> 00:02:52,150
But basically that is how we can pass the information.

40
00:02:52,460 --> 00:02:58,420
But now, of course, that is just one step of it because we also need to retrieve it.

41
00:02:58,940 --> 00:03:00,290
So let's retrieve it.

42
00:03:00,410 --> 00:03:01,580
And where would that be?

43
00:03:01,610 --> 00:03:05,490
Well, in our happy place detail activity, because that's where we are going to need it.

44
00:03:06,080 --> 00:03:08,300
So let's go ahead and.

45
00:03:09,720 --> 00:03:19,200
Create an object of our happy place model, so far, a happy place detail model will be our happy place

46
00:03:19,410 --> 00:03:27,420
model Nullable and then we check if the Internet has information, so has extra.

47
00:03:28,590 --> 00:03:37,560
Called main activity, that extra place detail, we called it like that, as you can see in our main

48
00:03:37,560 --> 00:03:43,470
activity, this is our companion object variable, this static variable that we have here that we now

49
00:03:43,470 --> 00:03:48,370
can use and can see if it has this specific name, then do something with it.

50
00:03:48,720 --> 00:03:51,390
So we're saying, OK, does it have an extra which has this name?

51
00:03:51,750 --> 00:03:55,290
And if it does, then run some code and that's what we're doing here.

52
00:03:55,320 --> 00:04:07,110
So we're saying assign the intense get a serializable extra main activity that.

53
00:04:09,300 --> 00:04:19,079
Extra heavy police detail as a happy place model, because it's not going to be in the form of a happy

54
00:04:19,079 --> 00:04:22,150
place model, so we want to cast it to be one.

55
00:04:22,530 --> 00:04:22,920
All right.

56
00:04:22,920 --> 00:04:23,970
So now it's going to be one.

57
00:04:25,520 --> 00:04:34,130
So now that we have assigned it, we can check is our happy place model or detail model not empty,

58
00:04:34,580 --> 00:04:38,210
so happy place model, not now.

59
00:04:41,400 --> 00:04:41,880
Then.

60
00:04:42,980 --> 00:04:51,770
We want to have an actual bar at the top, so I'm just going to use the tool bar, Happy Place Detail

61
00:04:52,370 --> 00:04:53,150
Action Bar.

62
00:04:55,160 --> 00:05:03,980
Then I'm going to say that it is going to be or it's going to have this back button, so support action

63
00:05:04,010 --> 00:05:04,400
bar.

64
00:05:07,190 --> 00:05:12,420
Set display home as unable to I'm going to say that's true.

65
00:05:13,070 --> 00:05:15,080
And then I'm going to set its title.

66
00:05:15,080 --> 00:05:22,730
So Support Action Bar, the title is going to be a happy place model the title.

67
00:05:23,240 --> 00:05:27,760
So whatever we had as the title in our happy place model.

68
00:05:27,770 --> 00:05:32,380
So the string here, that's going to be the title of our action bar.

69
00:05:33,080 --> 00:05:38,870
So instead of just having a happy place detail, as we currently have called it.

70
00:05:38,880 --> 00:05:39,590
So here.

71
00:05:41,350 --> 00:05:42,040
Our.

72
00:05:44,400 --> 00:05:48,780
Very top here hour toolbar, the current text is.

73
00:05:49,910 --> 00:05:51,050
We even have a text here.

74
00:05:51,170 --> 00:05:56,060
Actually, we don't have a text here, so now it's going to get a text, which is going to be the title

75
00:05:56,060 --> 00:05:57,830
of the Happy Place detail model.

76
00:06:00,340 --> 00:06:02,950
And then what should happen once we click on this thing?

77
00:06:03,490 --> 00:06:09,800
Well, then we want to set it as back pressed.

78
00:06:10,000 --> 00:06:18,370
OK, so once we click on our navigation element here, set navigation, I'll click listener on back

79
00:06:18,730 --> 00:06:21,530
pressed should be called OK.

80
00:06:21,670 --> 00:06:23,740
And at this point we can go ahead.

81
00:06:24,680 --> 00:06:27,350
And assign all of the different.

82
00:06:28,630 --> 00:06:34,570
Details here, so all of the different information, such as which image to use, which text to use

83
00:06:34,570 --> 00:06:40,210
and so forth, because we have here a complete image of you, which is Ivy Place image.

84
00:06:40,660 --> 00:06:45,120
This is the one that we want to populate with the image of the element that we clicked on.

85
00:06:45,400 --> 00:06:49,300
So here, if we click on this one, we want to have Holmer.

86
00:06:49,510 --> 00:06:51,940
So here, this image here should be Homerton.

87
00:06:53,210 --> 00:07:01,080
All right, so let's assign it let's go ahead and say on the score place image, that set image.

88
00:07:01,580 --> 00:07:02,840
So how did we store it?

89
00:07:03,170 --> 00:07:07,370
Well, we store the image as a string, which means we store it as a link.

90
00:07:07,640 --> 00:07:09,890
So we started as a you are I, so to speak.

91
00:07:09,900 --> 00:07:11,690
So set image, you are right.

92
00:07:12,410 --> 00:07:18,770
Which will be your parts, because now we need to bring it back into a URAI format and that will be

93
00:07:18,770 --> 00:07:21,680
our happy place detail model.

94
00:07:21,920 --> 00:07:22,790
Dot image.

95
00:07:24,270 --> 00:07:30,690
And of course, we need to import Urai, so let's do that real quick here, import this and now we can

96
00:07:30,690 --> 00:07:32,970
go ahead and set the same for our text here, of course.

97
00:07:33,270 --> 00:07:36,400
So what was the name of our description text here?

98
00:07:36,420 --> 00:07:38,500
I think TV description.

99
00:07:38,520 --> 00:07:39,960
So let's look at it yet.

100
00:07:39,990 --> 00:07:42,860
It was TV description, so let's use that.

101
00:07:43,890 --> 00:07:49,830
So let's set its text to Happy Place model is a model to be precise and description.

102
00:07:50,460 --> 00:07:55,320
And then TV underscore what we have OK with location.

103
00:07:55,890 --> 00:08:01,380
Text is going to be our happy place detail model location.

104
00:08:03,280 --> 00:08:08,000
All right, so now we can test that and see if it's actually going to work.

105
00:08:09,370 --> 00:08:19,690
And then while it's running, I want to also talk about a little other aspect of using our serializable.

106
00:08:19,690 --> 00:08:24,280
So serializable is one way, but there is another option for this.

107
00:08:24,280 --> 00:08:25,720
And we're going to look at that in a second.

108
00:08:27,390 --> 00:08:32,500
So first of all, let's test it, let's click on Holmer and we could see the Holmer image is populated.

109
00:08:32,500 --> 00:08:35,210
The test description and test location are the text here.

110
00:08:35,460 --> 00:08:37,200
So that worked flawlessly.

111
00:08:38,280 --> 00:08:38,760
Perfect.

112
00:08:39,100 --> 00:08:40,610
All right, and it's quick enough, right?

113
00:08:42,510 --> 00:08:49,590
But then when developing this, I came across Pasodoble versus Serializable, and that is something

114
00:08:49,590 --> 00:08:54,530
that you always can do, you can always improve your coding or your performance of your app.

115
00:08:54,870 --> 00:09:00,150
And of course, at one point, it doesn't really matter that much because in our case, I mean, the

116
00:09:00,150 --> 00:09:01,590
application is fast enough, right?

117
00:09:01,620 --> 00:09:05,430
So it's super fast even in the emulator, which is a super slow device.

118
00:09:05,820 --> 00:09:11,550
But still, if you look at it, there is an alternative to serializable, which is called personable.

119
00:09:11,910 --> 00:09:13,710
And you can check out this article here.

120
00:09:13,950 --> 00:09:21,960
But basically what he says is that using Soheir Pasodoble versus serializable and he says that using

121
00:09:21,960 --> 00:09:27,740
pasodoble is going to be significantly faster than using serializable.

122
00:09:28,110 --> 00:09:30,390
So it is like 10 times faster.

123
00:09:30,870 --> 00:09:31,340
All right.

124
00:09:31,350 --> 00:09:32,610
So let's try that.

125
00:09:33,700 --> 00:09:37,690
So how we do we make this happy place model Pasodoble?

126
00:09:37,720 --> 00:09:43,960
Well, you can just use Parcell Bolt here the keyword, and then it's going to complain, it's going

127
00:09:43,960 --> 00:09:48,390
to say, OK, you need to implement pasodoble methods and stuff.

128
00:09:48,400 --> 00:09:51,100
So let's let's add this implementation.

129
00:09:51,100 --> 00:09:56,740
You can see and add this constructor, but then it's complaining because strings need to be nullable

130
00:09:56,830 --> 00:09:57,540
for this to work.

131
00:09:57,550 --> 00:10:05,940
So let's add a bunch of question marks here for our strings so that it's not complaining anymore.

132
00:10:06,850 --> 00:10:07,380
All right.

133
00:10:08,350 --> 00:10:13,420
So once we've done that, the next thing we need to do is, of course, to go to our main activity where

134
00:10:13,420 --> 00:10:18,700
we passed in this detail and we started this.

135
00:10:20,170 --> 00:10:23,110
Intent, let's have a look can see.

136
00:10:23,970 --> 00:10:33,780
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

137
00:10:33,780 --> 00:10:37,140
can see in this case, it directly shows us the pasodoble option.

138
00:10:37,410 --> 00:10:41,280
But there is also one, which, of course, is the serializable that we used before.

139
00:10:41,490 --> 00:10:44,610
But now it's automatically going to use to pass the little option.

140
00:10:45,210 --> 00:10:51,870
And then the next thing we need to do is to check out the happy place, detail activity, because here

141
00:10:51,870 --> 00:10:54,540
we used to intend to get serializable of extra.

142
00:10:54,780 --> 00:10:58,140
So now I'm just going to use get Pasodoble Extra.

143
00:10:59,160 --> 00:11:00,280
And that's going to be it.

144
00:11:00,870 --> 00:11:08,760
So that's just another way of using objects that you want to pass around between different activities

145
00:11:08,760 --> 00:11:11,700
so you can use whatever way you prefer.

146
00:11:11,760 --> 00:11:16,560
I mean, serializable was the easier one, so to speak, but it's the less performant one.

147
00:11:16,560 --> 00:11:22,500
So if you really want to improve the performance of your application, then you can use Pasodoble here.

148
00:11:23,010 --> 00:11:27,230
And then, of course, when you do these changes, it's important to test if it's still going to work.

149
00:11:27,570 --> 00:11:31,730
And as you can see, it still seems to work totally fine.

150
00:11:32,680 --> 00:11:35,920
All right, so that was it for this video.

151
00:11:36,760 --> 00:11:42,700
Now you know how you can pass around the whole objects from one activity to another and you can use

152
00:11:42,700 --> 00:11:45,430
it there in order to populate, for example, your UI.

153
00:11:45,640 --> 00:11:49,960
And that will be super handy because you will need that functionality quite often.

154
00:11:50,380 --> 00:11:50,770
All right.

155
00:11:50,770 --> 00:11:52,420
So see you in the next video.

