1
00:00:04,759 --> 00:00:07,759
In the previous video we created a layout

2
00:00:07,759 --> 00:00:09,170
that we're going to be using for our

3
00:00:09,170 --> 00:00:11,269
button counter app, to show how to make a

4
00:00:11,269 --> 00:00:13,429
button to do something in Android.

5
00:00:13,429 --> 00:00:14,719
So open the project if you haven't already

6
00:00:14,719 --> 00:00:16,279
and then we're going to have a look at

7
00:00:16,279 --> 00:00:18,770
the code in the MainActivity class.

8
00:00:18,770 --> 00:00:21,020
Now Android Studio often opens up with most

9
00:00:21,020 --> 00:00:23,090
of the screen blank, with the project

10
00:00:23,090 --> 00:00:25,309
panes shrunk away to the left. Now I

11
00:00:25,309 --> 00:00:27,169
showed you how to get back by clicking

12
00:00:27,169 --> 00:00:28,880
them on the tab over to the left, here.

13
00:00:28,880 --> 00:00:31,899
You can also go to the View menu and

14
00:00:31,899 --> 00:00:35,780
choose Tool Windows and select Project

15
00:00:35,780 --> 00:00:38,750
from the list. Now obviously, because the

16
00:00:38,750 --> 00:00:40,190
project was selected, that's then

17
00:00:40,190 --> 00:00:41,570
disabled it. So I can go back again

18
00:00:41,570 --> 00:00:43,520
and select Project and bring it back on

19
00:00:43,520 --> 00:00:45,110
the screen again. So if you don't see it

20
00:00:45,110 --> 00:00:46,910
that's how to activate it, and you saw

21
00:00:46,910 --> 00:00:48,440
that there was a shortcut there as well.

22
00:00:48,440 --> 00:00:52,370
In my case, on a Mac its command 1, and that

23
00:00:52,370 --> 00:00:54,530
would be control 1 on a PC running

24
00:00:54,530 --> 00:00:58,340
Windows, and also the same for Linux. But

25
00:00:58,340 --> 00:00:59,870
it is actually worth checking, anytime

26
00:00:59,870 --> 00:01:02,720
you see these menu options, just to have

27
00:01:02,720 --> 00:01:03,770
a look at what the relevant 

28
00:01:03,770 --> 00:01:05,449
keyboard shortcut is for your operating

29
00:01:05,449 --> 00:01:08,149
system, because you will find that it's a

30
00:01:08,149 --> 00:01:09,950
lot more efficient, as you go through

31
00:01:09,950 --> 00:01:11,990
learning Android app development, to be

32
00:01:11,990 --> 00:01:14,210
using those keyboard shortcuts. But the

33
00:01:14,210 --> 00:01:15,649
quickest way to open the project pane is

34
00:01:15,649 --> 00:01:18,079
just to click on the tab, up here, at the

35
00:01:18,079 --> 00:01:20,509
top left hand corner. But I wanted to

36
00:01:20,509 --> 00:01:21,829
show you how to do it from the menu and

37
00:01:21,829 --> 00:01:23,719
also show you that the menus have that

38
00:01:23,719 --> 00:01:26,859
reminder of the keyboard shortcuts.

39
00:01:26,859 --> 00:01:29,299
Alright, so now that the project pane is

40
00:01:29,299 --> 00:01:31,579
open, to get to our code, we need to

41
00:01:31,579 --> 00:01:33,889
expand the app menu which, it's now

42
00:01:33,889 --> 00:01:35,689
expanded, but if it wasn't expanded it

43
00:01:35,689 --> 00:01:37,549
would look like that. Click on that and

44
00:01:37,549 --> 00:01:38,959
then also come down to here and click on

45
00:01:38,959 --> 00:01:41,600
Java, and you can see that the package name

46
00:01:41,600 --> 00:01:43,609
that we created using the reverse domain,

47
00:01:43,609 --> 00:01:46,909
in this case, is academy.learn

48
00:01:46,909 --> 00:01:50,659
programming.buttoncounterapp. This

49
00:01:50,659 --> 00:01:52,490
is where all our classes that contain

50
00:01:52,490 --> 00:01:54,170
the code for the app will actually

51
00:01:54,170 --> 00:01:55,490
eventually live, and I'll just expand

52
00:01:55,490 --> 00:01:57,529
that out so we can see the main activity

53
00:01:57,529 --> 00:01:59,990
there. Now there's two other directories

54
00:01:59,990 --> 00:02:03,759
in Java as well, and these ones down here,

55
00:02:03,759 --> 00:02:06,139
androidTest and test - you can see them

56
00:02:06,139 --> 00:02:07,609
in parentheses when I hover the mouse

57
00:02:07,609 --> 00:02:09,830
over them. And they're actually for our

58
00:02:09,830 --> 00:02:11,420
unit testing, both locally on the

59
00:02:11,420 --> 00:02:13,370
computer and also on an Android device

60
00:02:13,370 --> 00:02:15,799
or emulator. Now we're not going to be

61
00:02:15,799 --> 00:02:17,090
using those two directories in this

62
00:02:17,090 --> 00:02:18,520
course so you can safely ignore them and

63
00:02:18,520 --> 00:02:20,860
just focus on the first one - the one that

64
00:02:20,860 --> 00:02:23,560
hasn't got anything in parentheses. So

65
00:02:23,560 --> 00:02:24,640
make sure you've opened the correct

66
00:02:24,640 --> 00:02:26,020
folder and work in that, rather than

67
00:02:26,020 --> 00:02:28,900
those other two, and also don't be too

68
00:02:28,900 --> 00:02:31,000
concerned that the directory or the

69
00:02:31,000 --> 00:02:33,280
folder is called Java. You actually are

70
00:02:33,280 --> 00:02:35,290
in the right course! Now if you remember,

71
00:02:35,290 --> 00:02:38,410
Kotlin code is compiled to bytecode that

72
00:02:38,410 --> 00:02:40,750
runs in the java virtual machine. So it's

73
00:02:40,750 --> 00:02:42,880
pretty much the same bytecode that an

74
00:02:42,880 --> 00:02:44,910
equivalent Java program would produce.

75
00:02:44,910 --> 00:02:47,890
Now historically, this folder has been

76
00:02:47,890 --> 00:02:50,380
called Java. Now of course, Google may

77
00:02:50,380 --> 00:02:52,300
well change that in the future, so if you

78
00:02:52,300 --> 00:02:54,310
don't see MainActivity in a Java folder,

79
00:02:54,310 --> 00:02:56,080
then expand your Kotlin folder instead.

80
00:02:56,080 --> 00:02:58,060
But here we've got a Kotlin class

81
00:02:58,060 --> 00:03:00,160
called MainActivity that extends app

82
00:03:00,160 --> 00:03:01,780
compat activity, and you can see the code

83
00:03:01,780 --> 00:03:03,520
relating to this MainActivity class,

84
00:03:03,520 --> 00:03:05,590
over here in the right-hand side. If you

85
00:03:05,590 --> 00:03:06,640
don't see that you can just double click

86
00:03:06,640 --> 00:03:09,370
it to open it up. So again, here we've got

87
00:03:09,370 --> 00:03:11,350
a class, a Kotlin class called Main

88
00:03:11,350 --> 00:03:13,420
Activity, and you can see by this code up

89
00:03:13,420 --> 00:03:16,510
here, that it actually extends AppCompat

90
00:03:16,510 --> 00:03:18,820
Activity. Now remember, that I said that

91
00:03:18,820 --> 00:03:20,530
although we're using the latest version

92
00:03:20,530 --> 00:03:23,140
of the Android SDK, we can still create

93
00:03:23,140 --> 00:03:25,690
apps that run on older versions. Well

94
00:03:25,690 --> 00:03:27,730
it's the AppCompat library that makes

95
00:03:27,730 --> 00:03:28,480
that possible.

96
00:03:28,480 --> 00:03:30,490
Now when I first recorded this video

97
00:03:30,490 --> 00:03:32,440
before updating this course, there

98
00:03:32,440 --> 00:03:34,180
weren't any devices being used that knew

99
00:03:34,180 --> 00:03:35,709
what to do with a constraint layout,

100
00:03:35,709 --> 00:03:37,930
because Android N wasn't released then.

101
00:03:37,930 --> 00:03:40,330
When it was released, Google sent an

102
00:03:40,330 --> 00:03:42,520
updated AppCompat to all other

103
00:03:42,520 --> 00:03:45,790
supported devices, to enable code using

104
00:03:45,790 --> 00:03:47,890
the new constraint layout, to work on

105
00:03:47,890 --> 00:03:51,070
those devices as well. So all supported

106
00:03:51,070 --> 00:03:53,110
devices this time, means everything

107
00:03:53,110 --> 00:03:55,060
coming back to Gingerbread, and that goes

108
00:03:55,060 --> 00:03:57,880
all the way back to API 9. So what that

109
00:03:57,880 --> 00:04:00,880
means is that to us as developers, we can

110
00:04:00,880 --> 00:04:03,220
take advantage of the latest features, while

111
00:04:03,220 --> 00:04:04,780
still allowing our apps to run on older

112
00:04:04,780 --> 00:04:07,030
devices, and that, I'm sure you would

113
00:04:07,030 --> 00:04:09,550
agree, is seriously cool. Alright, so in the

114
00:04:09,550 --> 00:04:10,870
import section here, I'm just going to

115
00:04:10,870 --> 00:04:12,190
click on the plus and do that if 

116
00:04:12,190 --> 00:04:14,470
you can't see the list. We can see here

117
00:04:14,470 --> 00:04:16,959
that AppCompatActivity is imported

118
00:04:16,959 --> 00:04:19,829
from the android.support.v7.app

119
00:04:19,829 --> 00:04:22,390
library, and that's the code that Google

120
00:04:22,390 --> 00:04:25,930
updated back in 2016. Now this particular

121
00:04:25,930 --> 00:04:29,380
class, this MainActivity, is really

122
00:04:29,380 --> 00:04:32,000
simple. There's just a simple function here

123
00:04:32,000 --> 00:04:34,910
called onCreate - you can see that on line 8. Now

124
00:04:34,910 --> 00:04:36,140
when it's called by the Android

125
00:04:36,140 --> 00:04:38,300
framework, it gets passed something

126
00:04:38,300 --> 00:04:39,680
called a bundle, and you can see the

127
00:04:39,680 --> 00:04:41,150
reference to the Bundle here, again on

128
00:04:41,150 --> 00:04:43,460
line 8. And that's a Java class that's

129
00:04:43,460 --> 00:04:45,920
part of Android for passing data around.

130
00:04:45,920 --> 00:04:48,680
Now don't worry about it just yet. We're

131
00:04:48,680 --> 00:04:50,270
going to be looking at bundles in detail

132
00:04:50,270 --> 00:04:52,070
a little later, and that's because our

133
00:04:52,070 --> 00:04:53,090
app is going to be doing something

134
00:04:53,090 --> 00:04:56,570
strange when we rotate it. We're

135
00:04:56,570 --> 00:04:57,860
going to cover this bundle thing, though,

136
00:04:57,860 --> 00:05:00,380
when we look at how to fix that. But

137
00:05:00,380 --> 00:05:02,330
notice that I said that a bundle is a

138
00:05:02,330 --> 00:05:05,300
Java class. Now at the moment, most of the

139
00:05:05,300 --> 00:05:06,950
Android framework is actually written in

140
00:05:06,950 --> 00:05:08,990
Java, so we're going to be using a lot of

141
00:05:08,990 --> 00:05:11,330
Java classes in this course, even though

142
00:05:11,330 --> 00:05:13,910
the code we write will be Kotlin. When we

143
00:05:13,910 --> 00:05:15,260
look at the Android source code from

144
00:05:15,260 --> 00:05:17,300
time to time, it's going to be Java that

145
00:05:17,300 --> 00:05:19,100
we're going to be looking at. But don't

146
00:05:19,100 --> 00:05:20,390
worry, you certainly don't have to be an

147
00:05:20,390 --> 00:05:22,550
expert Java programmer. You just need to

148
00:05:22,550 --> 00:05:24,410
understand some very basic Java syntax

149
00:05:24,410 --> 00:05:26,390
relating to method declarations, and

150
00:05:26,390 --> 00:05:28,160
that's because functions are called

151
00:05:28,160 --> 00:05:31,820
methods in Java. Okay, so the first line of

152
00:05:31,820 --> 00:05:33,410
the function calls the super method - you

153
00:05:33,410 --> 00:05:35,720
can see this on line 9 - and it's passed

154
00:05:35,720 --> 00:05:37,940
to it the bundle, passing to it the

155
00:05:37,940 --> 00:05:39,830
bundle that this onCreate method received,

156
00:05:39,830 --> 00:05:41,960
the savedInstanceState, or saved

157
00:05:41,960 --> 00:05:44,210
InstanceState. And that means that if

158
00:05:44,210 --> 00:05:46,010
our onCreate method here, doesn't do

159
00:05:46,010 --> 00:05:48,020
anything with the bundle, the super

160
00:05:48,020 --> 00:05:49,430
method still gets a chance to do

161
00:05:49,430 --> 00:05:51,440
whatever it has to do with it. Again,

162
00:05:51,440 --> 00:05:52,610
we'll be seeing that a little bit later.

163
00:05:52,610 --> 00:05:55,180
And the last thing that this particular

164
00:05:55,180 --> 00:05:57,530
method does is called a setContentView

165
00:05:57,530 --> 00:06:00,350
method, telling it which layout we want

166
00:06:00,350 --> 00:06:02,630
to use for this activity. Now we saw that

167
00:06:02,630 --> 00:06:04,910
briefly in a previous video, when we

168
00:06:04,910 --> 00:06:06,860
changed the layout that the playing app

169
00:06:06,860 --> 00:06:08,900
displayed. Now one of the things that

170
00:06:08,900 --> 00:06:11,240
setContentView does is inflate the

171
00:06:11,240 --> 00:06:12,800
layout. We're going to be talking about

172
00:06:12,800 --> 00:06:14,870
layouts being inflated at various points

173
00:06:14,870 --> 00:06:16,820
in the course, so what does it actually mean

174
00:06:16,820 --> 00:06:19,700
to inflate a layout. Well it just really

175
00:06:19,700 --> 00:06:21,620
means that Android takes our xml

176
00:06:21,620 --> 00:06:24,020
definition for the layout, then creates

177
00:06:24,020 --> 00:06:26,360
all the widgets that we've defined in it.

178
00:06:26,360 --> 00:06:28,630
It then positions them on the screen,

179
00:06:28,630 --> 00:06:30,800
taking note of all the constraints,

180
00:06:30,800 --> 00:06:32,690
margins and other settings that we've

181
00:06:32,690 --> 00:06:34,820
defined. So as you can probably

182
00:06:34,820 --> 00:06:36,290
imagine, there's some pretty complex

183
00:06:36,290 --> 00:06:38,330
calculations going on while it does all

184
00:06:38,330 --> 00:06:40,910
this. But from our perspective, as far as

185
00:06:40,910 --> 00:06:43,640
we're concerned, inflating a layout just

186
00:06:43,640 --> 00:06:46,040
means creating the screen display from

187
00:06:46,040 --> 00:06:48,800
the XML in the layout file. So in our

188
00:06:48,800 --> 00:06:50,510
code here, we've told it to use the layout,

189
00:06:50,510 --> 00:06:53,690
R.layout.activity_

190
00:06:53,690 --> 00:06:55,550
main. Now that means it's going to look

191
00:06:55,550 --> 00:06:57,770
in the layout folder for a file called

192
00:06:57,770 --> 00:07:00,440
activity_main.xml and

193
00:07:00,440 --> 00:07:02,900
then use that to create the screen

194
00:07:02,900 --> 00:07:05,810
display. Alright, so we're only a few

195
00:07:05,810 --> 00:07:07,790
minutes into this video and I've already

196
00:07:07,790 --> 00:07:09,680
thrown a whole lot of jargon at you.

197
00:07:09,680 --> 00:07:12,830
Kotlin class, activity, support libraries

198
00:07:12,830 --> 00:07:14,810
super methods - it's probably all a bit

199
00:07:14,810 --> 00:07:16,930
confusing so I'd better explain some of it.

200
00:07:16,930 --> 00:07:19,100
Now one of the great things about

201
00:07:19,100 --> 00:07:20,870
Android programming, is that the

202
00:07:20,870 --> 00:07:23,060
framework does a great deal of work for

203
00:07:23,060 --> 00:07:25,790
us. There's still more than enough for us

204
00:07:25,790 --> 00:07:26,960
to do, though, so don't worry that you're

205
00:07:26,960 --> 00:07:28,400
going to have lots of time on your hands.

206
00:07:28,400 --> 00:07:30,950
But loads of fiddly things that have to

207
00:07:30,950 --> 00:07:33,110
be done, are actually done for us by

208
00:07:33,110 --> 00:07:36,800
Android. So a good analogy is to think of

209
00:07:36,800 --> 00:07:38,780
the Android framework, a bit like a

210
00:07:38,780 --> 00:07:41,600
pancake mix. So making good pancakes

211
00:07:41,600 --> 00:07:43,730
takes some skill, but before you can

212
00:07:43,730 --> 00:07:45,920
start you have to mix up eggs, flour,

213
00:07:45,920 --> 00:07:48,350
water and probably some other stuff that

214
00:07:48,350 --> 00:07:50,990
I don't know about. But it's tedious and

215
00:07:50,990 --> 00:07:52,640
hard work getting it all mixed just

216
00:07:52,640 --> 00:07:54,920
right, and that's before you start the

217
00:07:54,920 --> 00:07:56,750
important business of actually cooking

218
00:07:56,750 --> 00:07:59,660
the pancakes. So it's much easier to buy

219
00:07:59,660 --> 00:08:01,880
a pancake mix and use that. All the

220
00:08:01,880 --> 00:08:03,590
weighing and mixing has been done for us,

221
00:08:03,590 --> 00:08:05,600
so that we can concentrate on getting

222
00:08:05,600 --> 00:08:07,460
our pancakes light and fluffy and cooked

223
00:08:07,460 --> 00:08:09,770
on both sides. So the android framework

224
00:08:09,770 --> 00:08:12,380
actually does a similar job. Now in the

225
00:08:12,380 --> 00:08:14,150
old days, programmers had to do

226
00:08:14,150 --> 00:08:16,340
everything themselves, so they'd spend

227
00:08:16,340 --> 00:08:17,900
hours writing code to do basic

228
00:08:17,900 --> 00:08:19,910
things like, for example, checking if a

229
00:08:19,910 --> 00:08:22,040
key had been typed on the keyboard and

230
00:08:22,040 --> 00:08:23,780
working out where to display lines on

231
00:08:23,780 --> 00:08:25,640
the screen and where text should be

232
00:08:25,640 --> 00:08:27,470
printed, so it fits nicely in the boxes.

233
00:08:27,470 --> 00:08:29,930
So all of that sort of stuff had to

234
00:08:29,930 --> 00:08:32,030
be done before they could get around to

235
00:08:32,030 --> 00:08:34,099
creating the application that did the

236
00:08:34,099 --> 00:08:36,830
useful stuff. And in fact, if you go back

237
00:08:36,830 --> 00:08:39,229
a bit further it was even worse, and they'd

238
00:08:39,229 --> 00:08:40,789
even have to write code to do things

239
00:08:40,789 --> 00:08:43,130
like debouncing the keyboard. Now

240
00:08:43,130 --> 00:08:45,470
keyboards are mechanical switches, and

241
00:08:45,470 --> 00:08:47,570
when a key is pressed the mechanical

242
00:08:47,570 --> 00:08:49,520
contacts don't immediately connect. They

243
00:08:49,520 --> 00:08:51,590
sort of make him break quite a few times

244
00:08:51,590 --> 00:08:54,020
until the contact is fully made, and the

245
00:08:54,020 --> 00:08:55,370
mechanical parts are just pressing

246
00:08:55,370 --> 00:08:57,680
firmly against each other. So it happens

247
00:08:57,680 --> 00:08:59,510
with light switches in a house as well,

248
00:08:59,510 --> 00:09:01,550
and if you've ever operated a badly worn

249
00:09:01,550 --> 00:09:03,290
light switch, it can spark when the

250
00:09:03,290 --> 00:09:05,450
connection has been made - of course, the

251
00:09:05,450 --> 00:09:07,580
voltages are much higher and you don't get sparks

252
00:09:07,580 --> 00:09:09,440
from a keyboard, but it's really the same

253
00:09:09,440 --> 00:09:12,140
type of thing. So all that happens too

254
00:09:12,140 --> 00:09:13,640
quickly for us to notice the light

255
00:09:13,640 --> 00:09:15,950
flicker as it's turned on, but fast to a

256
00:09:15,950 --> 00:09:18,170
human is excruciatingly slow to a

257
00:09:18,170 --> 00:09:20,600
computer, and the computer can detect all

258
00:09:20,600 --> 00:09:22,280
those contacts while the mechanical

259
00:09:22,280 --> 00:09:25,010
keyboard switch settles down. Now if the

260
00:09:25,010 --> 00:09:26,900
keyboard wasn't debounced, you'd press

261
00:09:26,900 --> 00:09:28,220
a key and you'd get 8 or 12

262
00:09:28,220 --> 00:09:29,660
characters, perhaps, appearing on the

263
00:09:29,660 --> 00:09:32,480
screen. Now nowadays, with USB keyboards,

264
00:09:32,480 --> 00:09:34,100
it's all done on the keyboard itself, of

265
00:09:34,100 --> 00:09:36,800
course. So the Android framework is

266
00:09:36,800 --> 00:09:39,290
running all the time, doing a great deal

267
00:09:39,290 --> 00:09:42,170
of work for us, again, all the time. So, as

268
00:09:42,170 --> 00:09:43,850
a result, we don't have to write code to

269
00:09:43,850 --> 00:09:45,590
detect when a character was typed or a

270
00:09:45,590 --> 00:09:47,510
button is pressed. We actually leave that

271
00:09:47,510 --> 00:09:50,510
to Android and we just respond when

272
00:09:50,510 --> 00:09:52,250
Android tells our program that something

273
00:09:52,250 --> 00:09:54,500
interesting has happened. Now another

274
00:09:54,500 --> 00:09:57,500
example is orientation change. If we had

275
00:09:57,500 --> 00:10:00,080
to include code to monitor the

276
00:10:00,080 --> 00:10:02,390
motion detectors and include it in all

277
00:10:02,390 --> 00:10:04,160
your apps, you'd get a little bit bored.

278
00:10:04,160 --> 00:10:06,500
Instead, Android deals with orientation

279
00:10:06,500 --> 00:10:08,900
changes and we don't have to worry too

280
00:10:08,900 --> 00:10:10,640
much about them. And the way that 

281
00:10:10,640 --> 00:10:12,170
Android does deal with a change from

282
00:10:12,170 --> 00:10:13,730
portrait to landscape is pretty cool,

283
00:10:13,730 --> 00:10:15,530
and we're going to be looking at that a

284
00:10:15,530 --> 00:10:17,720
little bit later on, and that, in fact, is

285
00:10:17,720 --> 00:10:20,840
why we need to use Bundles. Alright, so

286
00:10:20,840 --> 00:10:22,610
the Android documentation is pretty good

287
00:10:22,610 --> 00:10:25,430
for most things. So you can check out

288
00:10:25,430 --> 00:10:26,900
more information on the framework and

289
00:10:26,900 --> 00:10:28,370
I'm going to just go into a browser here,

290
00:10:28,370 --> 00:10:30,200
and there'll be a link in the resources

291
00:10:30,200 --> 00:10:32,570
section of this video and anytime I

292
00:10:32,570 --> 00:10:34,340
mention a link, almost certainly it

293
00:10:34,340 --> 00:10:35,720
will be in the resources section on the

294
00:10:35,720 --> 00:10:38,270
video. And here's the Android website, as

295
00:10:38,270 --> 00:10:40,040
you can see there. Basically, Google's

296
00:10:40,040 --> 00:10:41,660
site for all things Android, so you can

297
00:10:41,660 --> 00:10:44,090
consider anything on there, on this site,

298
00:10:44,090 --> 00:10:45,830
as the definitive word on how

299
00:10:45,830 --> 00:10:47,780
Android works. There's a link on this

300
00:10:47,780 --> 00:10:49,970
page to activities. Come down here you

301
00:10:49,970 --> 00:10:51,500
can see Learn more Activities, I'm gonna click

302
00:10:51,500 --> 00:10:55,220
on that, and that gives us a bit of an

303
00:10:55,220 --> 00:10:57,770
overview of what an activity is. Al

304
00:10:57,770 --> 00:11:00,140
right so what is an activity? Well

305
00:11:00,140 --> 00:11:02,030
firstly, an application is made up of

306
00:11:02,030 --> 00:11:04,070
activities, which can launch other

307
00:11:04,070 --> 00:11:06,260
activities to perform different tasks.

308
00:11:06,260 --> 00:11:08,570
Now they are normally launched when the

309
00:11:08,570 --> 00:11:10,730
user clicks a button, or activates an

310
00:11:10,730 --> 00:11:12,500
option on a menu, for example.

311
00:11:12,500 --> 00:11:14,810
So when you launch your phone's dialer to

312
00:11:14,810 --> 00:11:16,480
make a phone call, that's an activity.

313
00:11:16,480 --> 00:11:18,980
When you're, say, viewing your contacts

314
00:11:18,980 --> 00:11:21,290
list, that's also an activity, and when

315
00:11:21,290 --> 00:11:23,420
you go on to edit a contact, that

316
00:11:23,420 --> 00:11:24,980
could be another activity, although

317
00:11:24,980 --> 00:11:26,660
Android has something called Fragments,

318
00:11:26,660 --> 00:11:28,550
that can also be used to display a user

319
00:11:28,550 --> 00:11:30,350
interface, but we're going to be looking

320
00:11:30,350 --> 00:11:32,870
at those later in the course. Now as you

321
00:11:32,870 --> 00:11:34,490
perform different actions in an

322
00:11:34,490 --> 00:11:36,680
app, you'll generally move from one activity

323
00:11:36,680 --> 00:11:39,650
to another. And Android keeps track of

324
00:11:39,650 --> 00:11:41,450
which activities you've used, and when

325
00:11:41,450 --> 00:11:43,550
you tap the back button, it closes the

326
00:11:43,550 --> 00:11:45,350
current activity and displays the

327
00:11:45,350 --> 00:11:47,810
previous one on the screen. Now we're

328
00:11:47,810 --> 00:11:49,490
going to be creating lots of activities,

329
00:11:49,490 --> 00:11:51,200
so you'll get plenty of practise at

330
00:11:51,200 --> 00:11:52,730
creating and using them for various

331
00:11:52,730 --> 00:11:55,280
things. And if you've never programmed in

332
00:11:55,280 --> 00:11:57,020
Kotlin before, you might be wondering

333
00:11:57,020 --> 00:11:59,780
what a Kotlin class is. Now we covered

334
00:11:59,780 --> 00:12:01,400
this in the Kotlin tutorial, in the

335
00:12:01,400 --> 00:12:03,530
previous section. Now that'll give you

336
00:12:03,530 --> 00:12:05,210
an introduction to the basics of

337
00:12:05,210 --> 00:12:07,130
programming in the Kotlin language, and

338
00:12:07,130 --> 00:12:08,660
will explain what things like classes

339
00:12:08,660 --> 00:12:10,910
are and how to create them. At the moment,

340
00:12:10,910 --> 00:12:12,350
though, think of them as building blocks

341
00:12:12,350 --> 00:12:14,000
that you can use to perform a function,

342
00:12:14,000 --> 00:12:16,340
or a group of related functions, when

343
00:12:16,340 --> 00:12:19,550
creating your programs. Now classes can

344
00:12:19,550 --> 00:12:21,470
be extended to add more functionality to

345
00:12:21,470 --> 00:12:23,960
change their behaviors. So, for a non-

346
00:12:23,960 --> 00:12:25,790
programming example, you could take a

347
00:12:25,790 --> 00:12:28,490
wooden pallet and extend it to make a

348
00:12:28,490 --> 00:12:30,710
packing crate. Now it's still got the

349
00:12:30,710 --> 00:12:32,810
properties of a pallet, and you can pile

350
00:12:32,810 --> 00:12:35,330
cartons in it and lift it with

351
00:12:35,330 --> 00:12:37,820
a forklift truck, but it's been extended.

352
00:12:37,820 --> 00:12:39,920
So now we could fill it with footballs

353
00:12:39,920 --> 00:12:41,270
and lift it without all the balls

354
00:12:41,270 --> 00:12:43,490
rolling off. Now trying to transport

355
00:12:43,490 --> 00:12:45,260
footballs on a wooden pallet wouldn't

356
00:12:45,260 --> 00:12:47,870
work out too well, but by extending the

357
00:12:47,870 --> 00:12:50,540
pallet by adding sides, we can use it

358
00:12:50,540 --> 00:12:52,910
for more than a basic pallet allows. And

359
00:12:52,910 --> 00:12:54,710
extending it further by perhaps adding a

360
00:12:54,710 --> 00:12:56,720
lid, then we could use it for transporting

361
00:12:56,720 --> 00:12:59,170
chickens, without them all jumping out.

362
00:12:59,170 --> 00:13:01,490
Alright, so the same principle applies

363
00:13:01,490 --> 00:13:04,490
to classes and in our simple code, as you

364
00:13:04,490 --> 00:13:07,580
go back to our Android Studio and into

365
00:13:07,580 --> 00:13:10,670
our class, the simple code here, the basic

366
00:13:10,670 --> 00:13:12,530
activity class has been extended and

367
00:13:12,530 --> 00:13:15,590
some additional code has been created, in

368
00:13:15,590 --> 00:13:17,360
this case, one line that displays our

369
00:13:17,360 --> 00:13:19,400
layout. So a new class called Main

370
00:13:19,400 --> 00:13:21,440
Activity is now an activity, that

371
00:13:21,440 --> 00:13:23,570
displays a particular layout.

372
00:13:23,570 --> 00:13:25,670
Now it's AppCompatActivity that's

373
00:13:25,670 --> 00:13:28,040
being extended, not activity as I

374
00:13:28,040 --> 00:13:30,170
mentioned earlier. So the principle is

375
00:13:30,170 --> 00:13:32,630
exactly the same, but the thing that's

376
00:13:32,630 --> 00:13:34,899
been extended can support other devices.

377
00:13:34,899 --> 00:13:37,430
Now all that code was generated by

378
00:13:37,430 --> 00:13:39,589
Android Studio when we chose the

379
00:13:39,589 --> 00:13:41,630
template. So what I'm going to do is end

380
00:13:41,630 --> 00:13:43,579
the video here, and in the next video

381
00:13:43,579 --> 00:13:45,949
we're going to start by making our code do

382
00:13:45,949 --> 00:13:47,660
a little bit more. So let's work on that

383
00:13:47,660 --> 00:13:50,649
in the next video.

