1
00:00:00,260 --> 00:00:03,640
And now let's actually delete this line of code here.

2
00:00:03,990 --> 00:00:10,200
And now let's actually create a listener for the spot in and send data on the server.

3
00:00:10,200 --> 00:00:15,840
So just step in here PTEN send data to a server that sits on click listener.

4
00:00:15,980 --> 00:00:17,230
OK new.

5
00:00:17,400 --> 00:00:23,300
And then here just hold the shift key on your keyboard and then press on the little Vicci on your keyboard.

6
00:00:23,600 --> 00:00:30,240
And now as you can see here the autocomplete feature of the Android studio is helping us to choose this

7
00:00:30,240 --> 00:00:31,540
option unclick listener.

8
00:00:31,660 --> 00:00:36,680
And now as you can see here inside the curly braces you can see this value dot dot dot.

9
00:00:36,840 --> 00:00:40,670
So choose this value and that person entered key on your keyboard.

10
00:00:40,980 --> 00:00:46,440
And now as you can see here these lines of code here are automatically put here by the Android studio.

11
00:00:46,650 --> 00:00:53,620
So here we have actually an anonymous in a class that actually implements this unclick listener interface.

12
00:00:53,730 --> 00:00:58,830
And because that anonymous in a class is actually implementing this unclick listener interface that

13
00:00:58,830 --> 00:01:03,610
class must provide an implementation for this Smurfit uncle.

14
00:01:03,810 --> 00:01:10,680
So now we are actually inside an anonymous inner class so here for example I can actually just typing

15
00:01:11,040 --> 00:01:15,520
database reference dot child.

16
00:01:15,630 --> 00:01:17,640
So now I can specify the child.

17
00:01:17,910 --> 00:01:22,580
And now I can actually just get the value of this as it takes it.

18
00:01:22,590 --> 00:01:23,390
EDT keep.

19
00:01:23,490 --> 00:01:25,590
So here we are going to specify the key.

20
00:01:25,620 --> 00:01:26,060
Right.

21
00:01:26,160 --> 00:01:31,470
So EDT key dot get text dot to a string.

22
00:01:31,800 --> 00:01:32,260
Right.

23
00:01:32,490 --> 00:01:40,430
And now I can say Dot said while you and here for the value you can put the value of these text it is

24
00:01:40,440 --> 00:01:41,190
de-value right.

25
00:01:41,190 --> 00:01:45,980
So EDT value that get tix to string.

26
00:01:46,290 --> 00:01:49,570
And then I can put a semicolon at the end of my statement.

27
00:01:49,890 --> 00:01:53,610
So as you can see here again let me actually just explain again.

28
00:01:53,880 --> 00:01:59,250
Actually we have this database reference that is referring to this instance as you can see here to this

29
00:01:59,260 --> 00:02:00,530
database instance.

30
00:02:00,780 --> 00:02:02,880
Now let me actually did it this value here.

31
00:02:04,440 --> 00:02:09,930
So here we have actually our reference database reference that is referring to this instance inside

32
00:02:09,960 --> 00:02:10,750
our database.

33
00:02:10,770 --> 00:02:11,340
Right.

34
00:02:11,760 --> 00:02:14,760
And now we say that tight.

35
00:02:14,880 --> 00:02:22,530
So here we want to actually create a child for this instance and the tide value is going to be key that

36
00:02:22,660 --> 00:02:24,260
takes that to history.

37
00:02:24,780 --> 00:02:30,360
And then we are going to actually call this method and that tight set value.

38
00:02:30,450 --> 00:02:36,080
So then we can actually specify the values the value that takes that to history.

39
00:02:36,450 --> 00:02:40,510
So now let's run our project and see what happens.

40
00:02:42,020 --> 00:02:44,130
Now let me actually open the web browser.

41
00:02:44,140 --> 00:02:46,890
Now let me show you the emulator here.

42
00:02:47,000 --> 00:02:58,770
So here let me specify the key so that you can be for example up more by name and the value can be phone.

43
00:02:59,480 --> 00:03:02,260
IPhone 7 right.

44
00:03:02,270 --> 00:03:06,070
And here let's actually click on this button send data to a server.

45
00:03:06,530 --> 00:03:11,730
And now here inside this database you can see that we have actually a child.

46
00:03:12,110 --> 00:03:17,790
And the key is mobility lane and the value is iPhone 7 right.

47
00:03:18,110 --> 00:03:20,520
So hopefully that makes sense.

48
00:03:20,520 --> 00:03:23,570
And now I want to show you something really important.

49
00:03:23,660 --> 00:03:32,030
So let's go back to what Android studio and here I can actually create are random actually unique ID

50
00:03:32,540 --> 00:03:34,220
for my keys.

51
00:03:34,220 --> 00:03:34,820
Right.

52
00:03:34,820 --> 00:03:37,530
So as you can see this is the key and this is the value.

53
00:03:37,610 --> 00:03:46,100
I can actually create a random ID for my keys so that there will be different keys for different values.

54
00:03:46,100 --> 00:03:48,250
So let me actually show you that here.

55
00:03:48,260 --> 00:03:54,720
So in order to create a random ID here first of all we need to actually create a variable of types think

56
00:03:54,980 --> 00:03:55,300
so.

57
00:03:55,340 --> 00:03:58,140
So it is unclear if I have actually just they've been.

58
00:03:58,490 --> 00:04:06,830
And the name of this variable can be for example unique ID and then I put an assignment operator here

59
00:04:08,120 --> 00:04:11,060
and then I'll refer to that to this database reference.

60
00:04:11,060 --> 00:04:16,370
So remember this database reference here actually holds the reference as you can see here.

61
00:04:16,670 --> 00:04:21,850
This database reference holds the reference to this database instance as you can see here.

62
00:04:21,860 --> 00:04:22,710
Right.

63
00:04:22,820 --> 00:04:28,160
So now here I am referring to this database reference dot dot.

64
00:04:28,400 --> 00:04:31,940
And here I can see push right push.

65
00:04:32,030 --> 00:04:38,270
When I actually call this push method and this reference is going to actually create our Random unique

66
00:04:38,360 --> 00:04:45,710
ID inside its database reference and it's going to be as a key that unique ID is going to be as a key

67
00:04:46,000 --> 00:04:46,800
right.

68
00:04:46,820 --> 00:04:57,210
And here in order to assign that unique ID to this variable unique ID here and say Dot get key right.

69
00:04:57,260 --> 00:05:00,520
And then I need to put a semicolon at the end of my statement.

70
00:05:00,750 --> 00:05:07,280
And now let's see how we can actually create a child with that unique ID.

71
00:05:07,310 --> 00:05:08,960
So in order to do that.

72
00:05:08,960 --> 00:05:20,870
So now let me actually just make this area disappeared and now I can say just database reference dot

73
00:05:21,830 --> 00:05:23,820
and here I can specify the child.

74
00:05:23,840 --> 00:05:29,930
So remember when I say database reference this database reference here is actually holding the reference

75
00:05:30,230 --> 00:05:31,390
to this instance.

76
00:05:31,430 --> 00:05:37,060
So I need to create children for this instance and then I can actually provide values for this instance.

77
00:05:37,070 --> 00:05:37,850
Right.

78
00:05:37,880 --> 00:05:45,380
So first of all I need to specify the child so the database reference that child and the child is going

79
00:05:45,380 --> 00:05:48,260
to be this unique ID write the child.

80
00:05:48,410 --> 00:05:49,020
Right.

81
00:05:49,070 --> 00:05:54,820
So you can say unique ID dot set value.

82
00:05:55,280 --> 00:05:59,760
And then here I can specify the value so the value can be a string value.

83
00:05:59,760 --> 00:06:09,160
And here I can say that this is of value and then I can put a semi-colon at the end of my statement.

84
00:06:09,200 --> 00:06:13,640
So now let's run our project and see what happens.

85
00:06:13,640 --> 00:06:16,140
So now as you can see here our press is actually running.

86
00:06:16,250 --> 00:06:22,700
So let me show you with the attitude of a browser and this is my emulator and here as you can see for

87
00:06:22,700 --> 00:06:25,980
the key I put this more by name an iPhone 7.

88
00:06:26,210 --> 00:06:26,910
Right.

89
00:06:26,930 --> 00:06:37,670
I can actually create other values so for the key which has actually just a computer name and for the

90
00:06:37,670 --> 00:06:46,550
value I can say match with pro MacBook Pro and here let's actually click on this send data to server

91
00:06:47,800 --> 00:06:53,590
and now it's going to actually create a new value here for me which is this one computer named Mike

92
00:06:53,750 --> 00:06:57,170
Rowe and it also created this value for me here.

93
00:06:57,410 --> 00:06:59,090
As you can see look at this key here.

94
00:06:59,150 --> 00:07:04,760
This key is actually a unique ID that is created by the firebase for me right.

95
00:07:04,760 --> 00:07:10,570
This key is not going to be similar to any other keys that are going to be created by the fireplace.

96
00:07:10,580 --> 00:07:12,590
So this is completely unique.

97
00:07:13,010 --> 00:07:16,140
And now we have actually a value right.

98
00:07:16,340 --> 00:07:21,870
So you can actually make all this key actually as a category.

99
00:07:21,980 --> 00:07:23,650
So lets see how we can do that.

100
00:07:23,870 --> 00:07:30,350
Let's actually go back to our Android studio and now let's create another actually another unique ID

101
00:07:30,620 --> 00:07:33,590
so we can say database reference.

102
00:07:34,040 --> 00:07:46,290
And here I can say that push and here I can say that child write database reference that push that child.

103
00:07:46,350 --> 00:07:52,360
So here let's actually specify the child so the child could be for example a child.

104
00:07:53,580 --> 00:07:56,560
And here are each and specify another child.

105
00:07:56,670 --> 00:08:02,570
So here this child is actually going to be the child of that unique ID.

106
00:08:02,580 --> 00:08:02,900
Right.

107
00:08:02,910 --> 00:08:04,320
I can specify another child.

108
00:08:04,330 --> 00:08:11,790
So let's actually just set a value to this child and he'll say set value.

109
00:08:12,270 --> 00:08:17,440
And then I put two double quotes here and and I can say what do you let's actually put a semicolon here

110
00:08:17,850 --> 00:08:22,380
and now let's actually run our project and see what happens.

111
00:08:24,980 --> 00:08:29,810
Now let me actually open my browser and this is my emulator.

112
00:08:30,020 --> 00:08:32,060
So let's actually click on this button again here.

113
00:08:32,060 --> 00:08:40,010
Send data to server and again as you can see here it actually created this unique idea here with disvalue.

114
00:08:40,030 --> 00:08:47,230
So again because this is actually a unique ID different keys can be here can be put here with different

115
00:08:47,230 --> 00:08:47,990
names right.

116
00:08:48,160 --> 00:08:52,850
But at different times with the same name can not be put here.

117
00:08:53,170 --> 00:08:59,270
So as you can see we have this key here and here we have this child which has this value.

118
00:08:59,440 --> 00:09:03,750
So this key is actually playing the role of a category.

119
00:09:03,850 --> 00:09:07,220
And inside this category we have this child and value.

120
00:09:07,420 --> 00:09:16,720
So let's see how we can actually access the values of these are actually keys the values of these instances.

121
00:09:16,750 --> 00:09:17,330
Right.

122
00:09:17,560 --> 00:09:20,830
So for now we have these children and we have these values.

123
00:09:20,890 --> 00:09:24,450
So how we can actually get these values from the database.

124
00:09:24,760 --> 00:09:27,240
And now let's actually go back to our Java code.

125
00:09:27,250 --> 00:09:35,800
Let's go back to our Android studio and now after the ending prentices of this listener for this PTEN

126
00:09:36,010 --> 00:09:41,920
send data to a server here I'm going and going to actually create a listener for this button Betty and

127
00:09:41,920 --> 00:09:43,480
get data from server.

128
00:09:43,690 --> 00:09:48,090
So as you can see here if I show you the emulator we have this button gets data from server.

129
00:09:48,220 --> 00:09:50,980
So let's actually create a listener for this spot.

130
00:09:51,010 --> 00:09:58,430
So here I can say BATNA get data from server that set unclick listener.

131
00:09:58,510 --> 00:10:00,260
And here I put the new keyboard.

132
00:10:00,550 --> 00:10:05,490
And then here I hold the shift key on my keyboard and then personally there Vicci on your keyboard.

133
00:10:05,710 --> 00:10:10,990
And now as you can see here the auto complete feature of Android studio is helping me to choose this

134
00:10:10,990 --> 00:10:11,400
option.

135
00:10:11,410 --> 00:10:16,670
Uncle Glassner and then choose it and then press on Enter key on your keyboard.

136
00:10:17,050 --> 00:10:23,050
And now as you can see here the autocomplete feature on Android stood You helped me to actually just

137
00:10:23,290 --> 00:10:29,290
put these lines of code here and now as you can see and as you know we have actually anonymous in a

138
00:10:29,290 --> 00:10:36,730
class that is implementing these unclick listener interface and it is actually providing a implement

139
00:10:36,850 --> 00:10:39,090
an implementation for this unclick method.

140
00:10:39,400 --> 00:10:45,580
So inside this enclave nymphet we need to put the codes in order to get the values that we have inside

141
00:10:45,580 --> 00:10:46,530
the database.

142
00:10:46,540 --> 00:10:49,180
So let's see how we can do that.

143
00:10:49,180 --> 00:10:52,660
So first of all we need to pro-white our listener.

144
00:10:52,660 --> 00:10:58,780
So now let me show you the web browser first of all we need to provide a listener for these children

145
00:10:58,810 --> 00:11:03,040
or for instance you can pro-white actually.

146
00:11:03,520 --> 00:11:06,060
Actually it is called value Lessner right.

147
00:11:06,070 --> 00:11:11,270
You can pro-white a value listener for each of these instances right.

148
00:11:11,320 --> 00:11:17,200
For example for this instance we can provide a listener for this one for this one or for any others.

149
00:11:17,200 --> 00:11:19,540
So let's go back to our Android studio.

150
00:11:19,930 --> 00:11:26,210
And now first of all for example I want to get the value of this keep right.

151
00:11:26,290 --> 00:11:27,750
I want to get the value of this key.

152
00:11:27,760 --> 00:11:29,580
So let's go back to our Android studio.

153
00:11:29,680 --> 00:11:34,450
So here I need to actually get our reference to this key.

154
00:11:34,660 --> 00:11:40,720
So if I click on this key here as you can see this actually you are right here is changed.

155
00:11:40,840 --> 00:11:41,650
Right.

156
00:11:41,650 --> 00:11:43,190
So it is called.

157
00:11:43,420 --> 00:11:45,600
Now we have actually a different you all.

158
00:11:45,820 --> 00:11:49,740
So first of all we need to access this key we need to get this key.

159
00:11:49,960 --> 00:11:55,140
So let me ask you to click on this one here and I going to show me the whole database here.

160
00:11:55,370 --> 00:12:00,530
So now I'm going to pro-white a listener are valueless in their 40s key.

161
00:12:00,740 --> 00:12:01,340
Right.

162
00:12:01,340 --> 00:12:09,350
So let's go back to what Android studio and now we need to actually get our defense to our firebase

163
00:12:09,500 --> 00:12:10,340
database.

164
00:12:10,340 --> 00:12:16,100
So if I scroll to the top here as you can see in line number two in eight we actually created just a

165
00:12:16,100 --> 00:12:22,490
variable which is after firebase database that holds the instance of the database that we are going

166
00:12:22,490 --> 00:12:23,910
to want to get right.

167
00:12:23,960 --> 00:12:32,180
So let's scroll down here and now I can here just say firebase database dot.

168
00:12:32,540 --> 00:12:36,070
And here I can get the difference right.

169
00:12:36,140 --> 00:12:37,430
Good defense.

170
00:12:37,460 --> 00:12:38,770
So here I want to get that there.

171
00:12:38,900 --> 00:12:40,300
Get the reference right.

172
00:12:40,580 --> 00:12:47,060
So I want to actually change the reference because let's say go to the just google crowd here to our

173
00:12:47,060 --> 00:12:48,600
Web browser as you can see.

174
00:12:48,620 --> 00:12:50,150
You want to get.

175
00:12:50,210 --> 00:12:52,040
Let's let's see the whole database.

176
00:12:52,200 --> 00:12:54,980
You want to get the value of this key right.

177
00:12:54,980 --> 00:12:55,900
That's the goal here.

178
00:12:55,910 --> 00:12:56,620
Right.

179
00:12:56,660 --> 00:13:00,230
So now all you need to have are reference to this key.

180
00:13:00,380 --> 00:13:02,700
So how we can do that in order to do that.

181
00:13:02,750 --> 00:13:07,270
First of all we need to actually refer to our firebase database instance.

182
00:13:07,430 --> 00:13:12,500
If I scroll to the top here as you can see inside this uncreate it in line number twenty eight we have

183
00:13:12,520 --> 00:13:15,660
actually an instance of type firebase database.

184
00:13:15,660 --> 00:13:16,460
Right.

185
00:13:16,790 --> 00:13:21,230
And now we want to actually change the reference to this key.

186
00:13:21,620 --> 00:13:24,320
This key here right because I want to get this value.

187
00:13:24,470 --> 00:13:30,960
So here I can say firebase database but get reference as you can see here.

188
00:13:31,100 --> 00:13:37,610
So we have free Moffats get reference with actually an argument of types 3 and a get to without arguments

189
00:13:37,700 --> 00:13:39,780
and gets a reference from Dorel.

190
00:13:39,890 --> 00:13:45,780
Let's choose this one get reference here that accepts one argument of types 3 and.

191
00:13:46,150 --> 00:13:48,750
And now I need to specify the argument.

192
00:13:48,750 --> 00:13:49,370
Right.

193
00:13:49,370 --> 00:13:52,800
So the argument is these key right.

194
00:13:52,820 --> 00:13:56,750
As you can see here because you want to get the reference to Diski here.

195
00:13:56,750 --> 00:14:04,640
So just highlight this key here and right click on it and then just click on copy and let's go back

196
00:14:04,700 --> 00:14:09,330
to our Android studio and instead of double quotes put this value.

197
00:14:09,860 --> 00:14:20,190
And now I can call this Mefford dot at add value event listeners so we need to actually provide a listener

198
00:14:20,700 --> 00:14:27,770
for this key so that when the data is changed this class here is going to be notified.

199
00:14:27,930 --> 00:14:33,650
So add value event listeners just press an interviewee on your keyboard as you can see here add value

200
00:14:33,650 --> 00:14:35,100
into listener.

201
00:14:35,100 --> 00:14:41,310
Now let me ask you to create a new line here so that you can see the value better thought Id value event

202
00:14:41,340 --> 00:14:43,400
listener and inside Apprentice's.

203
00:14:43,410 --> 00:14:49,590
I can't say new and then hold the shift key on your keyboard and then press and delay their key on your

204
00:14:49,590 --> 00:14:50,950
keyboard.

205
00:14:51,360 --> 00:14:57,360
And now just select this option here a value event listener and then press an Enter key on your keyboard.

206
00:14:57,630 --> 00:15:02,790
And now as you can see here these lines of code are actually automatically put here and now as you can

207
00:15:02,790 --> 00:15:06,810
see here we have an error and it says X expediter expect that a semicolon.

208
00:15:06,960 --> 00:15:12,030
So just put a semi-colon at the end of this prentices and now the error is gone.

209
00:15:12,030 --> 00:15:17,110
So if you have two Misfit's here the first one is on the path change.

210
00:15:17,250 --> 00:15:23,530
So this method is going to be called vended data is actually changed and it is going to be called another

211
00:15:23,530 --> 00:15:23,850
time.

212
00:15:23,850 --> 00:15:28,220
For example when this actually Meffert is going to be called.

213
00:15:28,350 --> 00:15:29,170
Right.

214
00:15:29,190 --> 00:15:33,250
So when I actually click on the spot button PTEN get data from server.

215
00:15:33,380 --> 00:15:34,560
This method is going to be called.

216
00:15:34,750 --> 00:15:40,340
And also the data here is changed this method is also going to be called on data change.

217
00:15:40,650 --> 00:15:46,340
So inside the curly braces of this agency you get this data and we have another MFL which is on canceled.

218
00:15:46,410 --> 00:15:50,430
And this is called When that data is actually canceled.

219
00:15:50,430 --> 00:15:55,520
So for example we want to get the data on the entire internet connection is actually gone.

220
00:15:55,620 --> 00:15:57,740
So in that case we can't actually get that data.

221
00:15:57,870 --> 00:16:00,650
And in that case this method is going to be called.

222
00:16:00,840 --> 00:16:09,060
So inside this on day to change I can just say just create a string variable in order to hold the value

223
00:16:09,060 --> 00:16:11,140
of this key stream.

224
00:16:11,250 --> 00:16:17,900
And here I can say value assignment operator and here as you can see we have this argument.

225
00:16:17,940 --> 00:16:20,200
So this argument holds this value.

226
00:16:20,310 --> 00:16:24,320
The value is key because we actually provided a listener for this key.

227
00:16:24,330 --> 00:16:25,220
Right.

228
00:16:25,230 --> 00:16:34,050
So here I can say something about you assignment operator date snapshot data snapshot that get value

229
00:16:34,890 --> 00:16:36,930
and then put a semicolon at the end of your statement.

230
00:16:36,930 --> 00:16:42,260
And here we have an error and it says incompatible types required Java that line.

231
00:16:42,270 --> 00:16:45,790
That's strange but it is found in Java that Langat object.

232
00:16:45,800 --> 00:16:51,720
So let's go inside Apprentice's in order to specify specify that this value is actually a string value.

233
00:16:51,720 --> 00:16:55,700
We can say three in which capital S that class.

234
00:16:56,040 --> 00:16:57,600
And now the error is gone.

235
00:16:57,600 --> 00:16:59,980
And here I can set this value to my take.

236
00:17:00,020 --> 00:17:05,410
It takes you so it takes the value that text value.

237
00:17:05,430 --> 00:17:08,250
Now let's run our project and see what happens.

238
00:17:08,250 --> 00:17:11,580
So now let me actually to just open the web browser.

239
00:17:11,640 --> 00:17:14,930
And now let me actually just open the emulator here.

240
00:17:17,140 --> 00:17:24,480
Now the emulator is here and now let's click on this get data from server and now as you can see here

241
00:17:24,690 --> 00:17:26,610
we successfully got this value.

242
00:17:26,610 --> 00:17:29,350
This is of value right.

243
00:17:29,370 --> 00:17:33,910
As you can see here disvalue is here for Diski.

244
00:17:34,050 --> 00:17:35,430
So hopefully that makes sense.

245
00:17:35,430 --> 00:17:38,970
And let's actually get the other values here for the other keys.

