1
00:00:00,210 --> 00:00:06,660
Hello students and this the holy grail we're going to go ahead and create another Android application.

2
00:00:06,690 --> 00:00:08,130
So let's just click on this.

3
00:00:08,130 --> 00:00:14,730
Start in your Android studio project and for the application and just they've here at sixty six dash

4
00:00:14,990 --> 00:00:18,890
of line capability of line capability.

5
00:00:18,970 --> 00:00:25,470
And you can specify the company domain package name and the project location and then click on next.

6
00:00:25,650 --> 00:00:31,360
And here to this minimum STK as the API 16 Android 4.1 jelly bean.

7
00:00:31,620 --> 00:00:35,640
And then click on next and here choose empty activity next.

8
00:00:35,640 --> 00:00:37,820
And here are just a click and finish.

9
00:00:37,830 --> 00:00:42,010
So here let's actually connect our application to the firebase.

10
00:00:42,030 --> 00:00:49,320
So now at the top just click on Tools and Firebrace And then here click on realtime database and click

11
00:00:49,320 --> 00:00:51,260
on Save and retrieve data.

12
00:00:51,600 --> 00:00:57,540
And first just you just need to click on Connect to firebase so you can see here this starting connect

13
00:00:57,540 --> 00:00:58,220
dialog.

14
00:00:58,290 --> 00:01:03,610
And here you can just see that we have actually created a new project.

15
00:01:03,630 --> 00:01:08,740
So if you want to actually create a new firebase project app 66 offline capability.

16
00:01:08,880 --> 00:01:14,930
So in this tutorial I will actually let you know about the offline capability of fireplace.

17
00:01:14,950 --> 00:01:22,150
So let's create a new project and then you can specify the country or region and then click on our connect

18
00:01:22,140 --> 00:01:23,100
to firebase.

19
00:01:23,100 --> 00:01:26,060
So here we can see that it says connecting our two firebase.

20
00:01:26,070 --> 00:01:30,140
So it's going to take some time in order to connect that application to the firebase.

21
00:01:30,210 --> 00:01:35,760
So we should actually wait a little bit here and now as you can see here it says firebase project create

22
00:01:35,760 --> 00:01:38,830
it and connect it locally to my real app.

23
00:01:38,850 --> 00:01:41,310
And here you can see that it says connected.

24
00:01:41,520 --> 00:01:46,050
So now we should do the second step and it says at the real time database to your app.

25
00:01:46,080 --> 00:01:50,340
So just click on the spot in here and here just accept changes.

26
00:01:50,340 --> 00:01:56,970
So now as you can see here it can actually make our application ready for using their real time database.

27
00:01:57,030 --> 00:02:02,470
And here are first of all it's actually the go inside this activity underline main the example.

28
00:02:02,680 --> 00:02:06,010
And now let's actually collapse this assistance here.

29
00:02:06,030 --> 00:02:12,270
This firebase assistant and here are essentially agitatedly to this hello world takes you here to get

30
00:02:12,270 --> 00:02:12,630
it.

31
00:02:12,870 --> 00:02:20,690
And now first let's actually write a text view or a text field so distasteful.

32
00:02:20,730 --> 00:02:22,700
Here say this takes viewless for folder.

33
00:02:22,890 --> 00:02:28,920
Just drag this plain text here and put it here inside this relatively out.

34
00:02:28,920 --> 00:02:30,980
And now let's write a button instead.

35
00:02:31,040 --> 00:02:34,800
We just want to just select and drag it here below this text field.

36
00:02:36,150 --> 00:02:37,070
And put it here.

37
00:02:37,090 --> 00:02:40,320
So now let's let's actually select this edit takes here.

38
00:02:40,500 --> 00:02:48,260
And for the editors step in here EDT data this actually deletes So here as you can see we have this

39
00:02:48,260 --> 00:02:50,920
dialogue and it says update usages as well.

40
00:02:50,920 --> 00:02:52,910
So here you can just click on yes.

41
00:02:53,350 --> 00:02:58,870
And for the name attribute here just delete this value and then person enter key on your keyboard and

42
00:02:59,080 --> 00:03:00,020
select the spot.

43
00:03:00,070 --> 00:03:09,100
And for the ideas they've been here between send data and sent it up and the person into a general keyword

44
00:03:09,700 --> 00:03:15,910
and then are here for the text that should be that have this button just typed in here sent data to

45
00:03:15,910 --> 00:03:21,080
set and then person entelechy on your keyboard.

46
00:03:21,080 --> 00:03:22,310
So let's actually go inside.

47
00:03:22,310 --> 00:03:27,570
Our main activity that have a file Let's actually just declare these objects here.

48
00:03:27,860 --> 00:03:35,110
So now the first one is actually an edit text so EDT data semicolon.

49
00:03:35,300 --> 00:03:36,920
And the second one is actually a button.

50
00:03:36,920 --> 00:03:44,270
So between and data semicolon and here inside is uncreate Meffert It's actually to initialize these

51
00:03:44,270 --> 00:03:45,110
variables.

52
00:03:45,230 --> 00:03:50,720
So it is the data assignment operator and you literally just create this object.

53
00:03:50,720 --> 00:03:59,480
First we need to cast this object to an edit text object find view by ID or that Id that EDT data.

54
00:03:59,650 --> 00:04:02,300
And then at the end of your statements you need to put a semi-colon.

55
00:04:02,450 --> 00:04:07,790
And here we need to actually to initialize our part in PTEN send data assignment operator and he'll

56
00:04:07,790 --> 00:04:15,870
essentially cast this object to our putten object find view by id Artaud ID dot between send data.

57
00:04:16,010 --> 00:04:21,860
So as you can see here it cannot actually recognize our IDs so let's actually go inside our activity

58
00:04:21,860 --> 00:04:26,320
underlaid minute example here and here as you can see I actually made a mistake.

59
00:04:26,600 --> 00:04:31,110
And here we need to put PTEN sent data.

60
00:04:31,670 --> 00:04:34,620
So here I just need to press on until she on my keyboard.

61
00:04:34,940 --> 00:04:41,150
So let's go back to her domain activity class so PTEN sent data and then I need to press put a semicolon

62
00:04:41,150 --> 00:04:42,700
at the end of my statement.

63
00:04:42,800 --> 00:04:48,020
So he'll actually make the Spartan disobedience and date hot button our listeners with the clicks of

64
00:04:48,020 --> 00:04:55,890
the users to send data that said unclick listener new view that unclick listener.

65
00:04:56,060 --> 00:05:05,130
So here Enceladus uncle Anklage method we can actually put our own logic so here first of all this actually

66
00:05:05,130 --> 00:05:06,970
creates somebody else inside.

67
00:05:06,980 --> 00:05:08,410
Our main activity class.

68
00:05:08,520 --> 00:05:18,220
So the first one is our Firebrace firebase database and the name of my valuable is database semi-colon.

69
00:05:18,240 --> 00:05:21,730
So as you can see here I'm just declaring my variable here right.

70
00:05:21,750 --> 00:05:23,950
I'm not initializing my variable.

71
00:05:24,120 --> 00:05:26,030
I'm just declaring here.

72
00:05:26,100 --> 00:05:32,220
Now let's actually declare another variable of type database reference and the name of the variable

73
00:05:32,220 --> 00:05:33,680
is they have a reference.

74
00:05:33,720 --> 00:05:38,170
So now let's actually initialize our variables here inside our uncreate Smurfette.

75
00:05:38,190 --> 00:05:42,470
So here I can say a database right.

76
00:05:42,570 --> 00:05:49,710
Assignment operator firebase database that get instance semicolon and then lets actually initialize

77
00:05:49,710 --> 00:05:51,130
our database reference.

78
00:05:51,300 --> 00:05:58,100
So database reference assignment operator database that gets reference semi-colon.

79
00:05:58,350 --> 00:05:58,740
Right.

80
00:05:58,830 --> 00:06:02,470
So now I want to talk about offline capability.

81
00:06:02,700 --> 00:06:05,080
So what do you mean by offline capability.

82
00:06:05,310 --> 00:06:12,180
So the offline capability is going to actually enable your application to actually interact with a database

83
00:06:12,500 --> 00:06:16,910
of when the internet connection is actually gone.

84
00:06:17,100 --> 00:06:17,470
Right.

85
00:06:17,550 --> 00:06:21,990
So for example it's actually let me just put these lines of code here.

86
00:06:22,140 --> 00:06:25,640
And when we run our project and it will make more sense.

87
00:06:25,650 --> 00:06:30,680
So first of all I just need to type in here database here.

88
00:06:30,780 --> 00:06:38,600
I'm referring to the name of this valuable database that says persistence enabled and this method actually

89
00:06:38,640 --> 00:06:40,260
accepts a boolean variable.

90
00:06:40,470 --> 00:06:44,910
So of here we just need to pass a boolean value right.

91
00:06:44,940 --> 00:06:53,100
So here I can say true because I want to enable the offline capability of the firebase for my application

92
00:06:53,400 --> 00:06:56,190
I need to pass the value true for this method.

93
00:06:56,250 --> 00:07:00,230
So a database that says persistence enabled truth.

94
00:07:00,510 --> 00:07:08,130
And here I can say that database reference that cheap sinked true.

95
00:07:08,160 --> 00:07:16,890
So these are the two lines of code that we should put here in order to actually enable the offline capability

96
00:07:17,130 --> 00:07:18,220
and that's all.

97
00:07:18,540 --> 00:07:23,540
So that was actually sent this actually just set a value for our node.

98
00:07:23,580 --> 00:07:31,970
So now I can just type in here database reference dots set value.

99
00:07:32,520 --> 00:07:38,350
And here I can say for example some value some value right.

100
00:07:38,530 --> 00:07:47,520
And now let's actually run our project just a click and run app here and now it's actually a little

101
00:07:47,520 --> 00:07:48,330
bit here.

102
00:07:48,570 --> 00:07:53,530
Here we need to choose one of these devices one of these virtual devices.

103
00:07:53,550 --> 00:07:55,410
And then I just click on OK.

104
00:07:55,470 --> 00:07:58,790
So as you can see here our application crashed.

105
00:07:58,950 --> 00:07:59,690
Right.

106
00:07:59,700 --> 00:08:04,280
So let's go to Android studio and here able to show you why our application crashed.

107
00:08:04,290 --> 00:08:09,810
First of all in order to see of why your application crashed at the bottom you just need to click on

108
00:08:09,810 --> 00:08:12,410
this android monitor here.

109
00:08:12,630 --> 00:08:13,190
Right.

110
00:08:13,230 --> 00:08:16,080
And here you can see what's going on here.

111
00:08:16,080 --> 00:08:22,690
Let's actually make this area just bigger and you just need to look at these codes.

112
00:08:22,690 --> 00:08:26,520
You can look at these texts that are in red.

113
00:08:26,700 --> 00:08:29,930
And here it says fatal exception made.

114
00:08:30,180 --> 00:08:33,760
So Maine means actually in the forget.

115
00:08:33,780 --> 00:08:34,740
The main freight.

116
00:08:34,980 --> 00:08:38,960
And as you can see it says here you can actually find the cause of this error.

117
00:08:38,960 --> 00:08:42,020
It says jobs that landed at runtime exception.

118
00:08:42,030 --> 00:08:47,520
So this is the type of this exception run pump exception is actually an exception that occurred when

119
00:08:47,520 --> 00:08:50,100
you actually when you are running your application.

120
00:08:50,100 --> 00:08:50,880
Right.

121
00:08:50,880 --> 00:08:57,210
So when we tried to run our application this error occurred and here as you can see it says 66 of brain

122
00:08:57,210 --> 00:08:58,910
capability has stopped.

123
00:08:59,250 --> 00:09:03,090
And here it says Unable to start activity component info.

124
00:09:03,210 --> 00:09:05,250
So these are the info overnight activity.

125
00:09:05,460 --> 00:09:07,950
And here is actually scroll to the left.

126
00:09:07,950 --> 00:09:14,970
And here it says let's scroll to the right as you can see here it says come that Google that firebase

127
00:09:14,970 --> 00:09:17,890
that database that database acception.

128
00:09:18,060 --> 00:09:20,790
So this is actually on our database exception.

129
00:09:20,790 --> 00:09:29,310
And here it says calls to set persistence enabled must be made before any other uses of file based database

130
00:09:29,340 --> 00:09:30,270
instance.

131
00:09:30,270 --> 00:09:38,330
So here you can see that it says that V must actually call the said persistence in a belt method or

132
00:09:38,340 --> 00:09:43,480
before any other usage of firebase database instance.

133
00:09:43,500 --> 00:09:44,620
So what does this mean.

134
00:09:44,820 --> 00:09:48,560
So this actually is just go to our codes here.

135
00:09:48,810 --> 00:09:51,560
As you can see inside our uncreate Smurfette.

136
00:09:51,840 --> 00:09:57,210
First of all we actually initialized our database instance right.

137
00:09:57,480 --> 00:10:00,660
And then we actually called this method.

138
00:10:00,660 --> 00:10:02,860
So this is not right as the here.

139
00:10:02,950 --> 00:10:10,590
It says that first we should call this method before any other usage of firebase database instance.

140
00:10:10,600 --> 00:10:13,140
So here let me actually show you this area.

141
00:10:13,180 --> 00:10:16,210
Again let me show you these texts.

142
00:10:16,210 --> 00:10:22,900
It says this method must be made before any other usage of firebase database is this.

143
00:10:22,900 --> 00:10:27,110
So now as you can see it is actually just caught this line of code here.

144
00:10:27,310 --> 00:10:33,310
So if you are using a match just hold the common key on your keyboard and then press on the letter X

145
00:10:33,310 --> 00:10:34,440
key on your keyboard.

146
00:10:34,510 --> 00:10:39,100
And if you are using a Windows machine just hold the control key on your keyboard and then press on

147
00:10:39,100 --> 00:10:47,260
the letter X key on your keyboard in order to cut this line of code and put it here before this line

148
00:10:47,260 --> 00:10:50,330
of code here before using the firebase database instance.

149
00:10:50,380 --> 00:10:53,470
So here I can just paste it here right.

150
00:10:53,530 --> 00:11:02,020
And in this way as you can see we are actually using this method before using the firebase database

151
00:11:02,020 --> 00:11:02,750
instance.

152
00:11:02,950 --> 00:11:05,550
So again we are going to have a problem.

153
00:11:05,560 --> 00:11:10,240
So but now it's actually on our project and then I'm going to actually let you know what is this.

154
00:11:10,310 --> 00:11:10,840
Right.

155
00:11:10,930 --> 00:11:13,550
We may actually encounter another problem.

156
00:11:13,720 --> 00:11:15,440
So let's run our project again.

157
00:11:15,460 --> 00:11:17,370
Let me show you the emulator here.

158
00:11:20,810 --> 00:11:23,030
So again our application crashed.

159
00:11:23,060 --> 00:11:26,570
So let's see why this time our application crashed again.

160
00:11:26,780 --> 00:11:31,460
We should go to the Android studio and then click on this android monitor at the bottom.

161
00:11:32,090 --> 00:11:35,710
And here let me make this area just bigger.

162
00:11:35,900 --> 00:11:39,750
And here again we should look at these lines of code that are in red.

163
00:11:40,100 --> 00:11:44,260
And here again it says we have actually our runtime exception.

164
00:11:44,260 --> 00:11:51,690
And now let me actually scroll to the right and here it says Java the land dot null pointer exception.

165
00:11:51,770 --> 00:11:59,000
So it says attempt to invoke virtual Meffert void com that Google that firebase that database that firebase

166
00:11:59,000 --> 00:12:06,020
database that says set persistence enabled boolean on a null object reference as you can see here you

167
00:12:06,020 --> 00:12:09,880
are calling a method on a null object reference.

168
00:12:09,890 --> 00:12:11,810
So this is actually an exception.

169
00:12:11,840 --> 00:12:13,810
So let me show you why this error occurs.

170
00:12:14,030 --> 00:12:21,620
As you can see here in line number 19 we declared are valuable which is of type firebase database in

171
00:12:21,830 --> 00:12:22,130
here.

172
00:12:22,130 --> 00:12:22,770
Right.

173
00:12:22,850 --> 00:12:24,820
And the name of our valuable is database.

174
00:12:25,130 --> 00:12:26,080
As you can see here.

175
00:12:26,090 --> 00:12:28,250
I didn't initialize this variable.

176
00:12:28,250 --> 00:12:30,350
I just declared this variable.

177
00:12:30,520 --> 00:12:36,220
And inside our uncreate method before I initialize this variable.

178
00:12:36,290 --> 00:12:38,770
As you can see here I use this method.

179
00:12:38,840 --> 00:12:45,190
So in line number 44 I use I actually I actually initialize the Smurfette But in line number 52 are

180
00:12:45,220 --> 00:12:46,700
used this method.

181
00:12:46,700 --> 00:12:50,340
So this database here is actually not.

182
00:12:50,630 --> 00:12:56,760
And if you are calling the sniffer said persistence enabled we are calling this Nefert on a null object.

183
00:12:56,780 --> 00:12:59,310
This these are valuable database.

184
00:12:59,330 --> 00:13:06,100
As you can see is not quite because in line number 44 we just initialized it.

185
00:13:06,350 --> 00:13:10,500
And before this line of code here as you can see here we did it initialize.

186
00:13:10,580 --> 00:13:17,060
So now in line number for it is if to this database where the event is actually null and you're calling

187
00:13:17,060 --> 00:13:20,370
the Smurfette on a null object on a null variable.

188
00:13:20,480 --> 00:13:25,230
So it is going to actually cause an error and our application is going to crash.

189
00:13:25,520 --> 00:13:32,560
So in order to solve this problem I can just delete this database here and here I can say firebase database

190
00:13:33,120 --> 00:13:38,970
dot get instance that sets persistence enable true.

191
00:13:39,020 --> 00:13:39,500
Right.

192
00:13:39,650 --> 00:13:43,650
So in this way it is much more better.

193
00:13:44,450 --> 00:13:48,070
So now it's actually our project again.

194
00:13:48,110 --> 00:13:50,510
Now let me show you the emulator.

195
00:13:50,510 --> 00:13:53,760
Now as you can see here no errors occurred here.

196
00:13:54,040 --> 00:13:56,950
And that application is actually running on this emulator.

197
00:13:57,050 --> 00:14:03,110
So let me show you the web browser here and now I just need to go to as you can see here you just need

198
00:14:03,110 --> 00:14:07,700
to put this you are in here and then click on go to console.

199
00:14:07,760 --> 00:14:12,940
And here you should click on this app 5:54 dash of line capability here.

200
00:14:12,950 --> 00:14:14,470
So this is our project right.

201
00:14:14,480 --> 00:14:20,280
Just click on it and then click on database and click on rules.

202
00:14:20,300 --> 00:14:26,630
Just click on this rules tab here and here let's again change these rules so just delete these exclamation

203
00:14:26,650 --> 00:14:32,540
marks and put an equal operator here and again just delete this exclamation mark and put an equal operator

204
00:14:32,900 --> 00:14:34,590
and then click and publish.

205
00:14:34,880 --> 00:14:38,130
So now it's going to actually publish the rules as you can see here.

206
00:14:38,390 --> 00:14:41,910
And here again just click on the state bar tab here.

207
00:14:42,390 --> 00:14:44,820
And now this is our note right.

208
00:14:44,840 --> 00:14:50,650
So here I want to actually just tell the wife right off.

209
00:14:50,720 --> 00:14:50,980
Right.

210
00:14:50,990 --> 00:14:53,670
As you can see here my wife is actually on now.

211
00:14:53,700 --> 00:14:55,540
You want to turn my wife off.

212
00:14:55,550 --> 00:14:59,380
So now as you can see here my wife is now turned off.

213
00:14:59,390 --> 00:15:00,080
Right.

214
00:15:00,080 --> 00:15:07,740
So now let me show you the emulator and now let's actually just click on the spot and send data to server.

215
00:15:08,210 --> 00:15:14,210
As you can see here I just clicked on this button and now I'm able to actually turn my phone on.

216
00:15:14,210 --> 00:15:17,340
So now I turn to my wife right on.

217
00:15:17,450 --> 00:15:18,170
Right.

218
00:15:18,200 --> 00:15:23,390
And now as you can see here this values some value here is actually here.

219
00:15:23,390 --> 00:15:23,970
Right.

220
00:15:24,230 --> 00:15:32,300
So if you have noticed here I actually first turned to my wife right off and then I clicked on the spot

221
00:15:32,320 --> 00:15:40,550
in and when I turned my wife on again this value is actually sent to the server and we can see the value

222
00:15:40,550 --> 00:15:40,850
here.

223
00:15:40,880 --> 00:15:44,480
And that's the offline capability of Firebrace.

224
00:15:44,480 --> 00:15:48,530
And this is I think the best feature of the file by spackled.

225
00:15:48,560 --> 00:15:50,080
So this is very nice.

226
00:15:50,090 --> 00:15:57,680
So if I go back to android studio by just putting two lines of code we did manage to use the offline

227
00:15:57,680 --> 00:15:59,900
capability as you can see here.

228
00:15:59,900 --> 00:16:07,170
We did manage to use the offline capability and we could actually use it for our great applications.

229
00:16:07,220 --> 00:16:08,180
Right.

230
00:16:08,180 --> 00:16:13,340
So now here I just I'm just sending this value some value so I can actually change this value to the

231
00:16:13,640 --> 00:16:17,850
value of the EDT date hot that just text that to strike.

232
00:16:17,960 --> 00:16:21,690
I could actually send the value of this and it takes to the server.

233
00:16:21,740 --> 00:16:25,320
So I think that's enough for this tutorial.

234
00:16:25,760 --> 00:16:32,750
And if you have any questions about the of line capability of the firebase or please post the discussion

235
00:16:32,750 --> 00:16:36,440
in the course and then I'll do my best to answer all of your questions.

236
00:16:36,440 --> 00:16:39,780
Thank you very much for watching and I'll see you in the next story or.

