1
00:00:00,145 --> 00:00:02,731
(bright music)

2
00:00:02,731 --> 00:00:05,491
(clicking)

3
00:00:05,491 --> 00:00:07,160
In the previous video, we wrote the code

4
00:00:07,160 --> 00:00:09,160
to use AddEdit fragment to allow

5
00:00:09,160 --> 00:00:11,400
new task details to be entered.

6
00:00:11,400 --> 00:00:13,960
Our main activity now uses two fragments,

7
00:00:13,960 --> 00:00:16,963
MainActivity fragment and AddEdit fragment.

8
00:00:16,963 --> 00:00:20,600
AddEdit fragment is added and removed as we need it,

9
00:00:20,600 --> 00:00:23,020
but MainActivity fragment is included

10
00:00:23,020 --> 00:00:24,650
in the activities layout,

11
00:00:24,650 --> 00:00:26,980
and we're seeing that it can't be removed.

12
00:00:26,980 --> 00:00:28,780
Because MainActivity fragment is part

13
00:00:28,780 --> 00:00:31,880
of the activity's layout, it's easy to see

14
00:00:31,880 --> 00:00:34,700
how its lifecycle must be closely linked

15
00:00:34,700 --> 00:00:36,540
to the activity lifecycle.

16
00:00:36,540 --> 00:00:38,900
When the activity gets destroyed for example,

17
00:00:38,900 --> 00:00:41,000
the fragment also gets destroyed.

18
00:00:41,000 --> 00:00:43,580
But it may be less obvious how the full

19
00:00:43,580 --> 00:00:46,960
activity lifecycle effects our AddEdit fragment,

20
00:00:46,960 --> 00:00:48,780
because the fragment doesn't even exist

21
00:00:48,780 --> 00:00:50,660
when we first run the app.

22
00:00:50,660 --> 00:00:52,120
For that reason, I'm gonna start off

23
00:00:52,120 --> 00:00:53,770
with MainActivity fragment,

24
00:00:53,770 --> 00:00:57,370
then we'll relate what we learn to the AddEdit fragment.

25
00:00:57,370 --> 00:00:59,910
So let's start by having another look at the Google guide

26
00:00:59,910 --> 00:01:01,510
that we've looked previously at.

27
00:01:03,330 --> 00:01:04,962
This is the components guide.

28
00:01:06,650 --> 00:01:08,640
So we're gonna see how the fragment lifecycle

29
00:01:08,640 --> 00:01:12,600
fits into and is controlled by the activity lifecycle.

30
00:01:12,600 --> 00:01:14,537
You may want to review the videos about the activity

31
00:01:14,537 --> 00:01:17,800
lifecycle in section five, because I'll be referring

32
00:01:17,800 --> 00:01:21,070
to the activity lifecycle a lot in this video.

33
00:01:21,070 --> 00:01:24,210
Alright, so this second paragraph on this page

34
00:01:24,210 --> 00:01:28,120
talks about a fragment always being hosted in an activity.

35
00:01:28,120 --> 00:01:30,340
So you can't just create and display a fragment.

36
00:01:30,340 --> 00:01:32,290
They're always in an activity.

37
00:01:32,290 --> 00:01:34,540
The same fragment class can be displayed

38
00:01:34,540 --> 00:01:36,040
in several activities,

39
00:01:36,040 --> 00:01:38,490
and that's one of the advantages of using them.

40
00:01:38,490 --> 00:01:40,880
Now as an example, we could allow our users

41
00:01:40,880 --> 00:01:44,260
to edit task details from the report screen

42
00:01:44,260 --> 00:01:46,500
as well as, from the main task list.

43
00:01:46,500 --> 00:01:49,410
We'd use the same fragment if we wanted to do that.

44
00:01:49,410 --> 00:01:51,750
And wouldn't have to duplicate all the edited fragment

45
00:01:51,750 --> 00:01:54,870
code in the error reports activity.

46
00:01:54,870 --> 00:01:56,680
So the first paragraph talks about,

47
00:01:56,680 --> 00:01:59,760
you can think of a fragment as a modular section

48
00:01:59,760 --> 00:02:02,730
of an activity, which has its own lifecycle,

49
00:02:02,730 --> 00:02:05,010
receives its own input events,

50
00:02:05,010 --> 00:02:06,610
and which you can add or remove

51
00:02:06,610 --> 00:02:08,169
while the activity is running,

52
00:02:08,169 --> 00:02:10,009
sort of like a sub activity that

53
00:02:10,009 --> 00:02:12,570
you can reuse in different activities.

54
00:02:12,570 --> 00:02:14,710
Now moving down to this third paragraph,

55
00:02:14,710 --> 00:02:16,620
it discusses where the fragment lives

56
00:02:16,620 --> 00:02:19,750
in the activity's layout or view hierarchy

57
00:02:19,750 --> 00:02:21,450
as Google calls them.

58
00:02:21,450 --> 00:02:24,100
So we've used both methods, MainActivity fragment

59
00:02:24,100 --> 00:02:26,760
lives in a fragment element of the layout,

60
00:02:26,760 --> 00:02:29,370
where as the AddEdit fragment is added

61
00:02:29,370 --> 00:02:32,840
to a frame layout view group, as when we need it.

62
00:02:32,840 --> 00:02:34,150
Now that should make a lot more sense

63
00:02:34,150 --> 00:02:35,800
now that we've seen it working.

64
00:02:35,800 --> 00:02:38,550
So let's move now on to the lifecycle.

65
00:02:38,550 --> 00:02:41,490
So we come over here and click on Creating a Fragment.

66
00:02:41,490 --> 00:02:43,250
There's a brief diagram here,

67
00:02:43,250 --> 00:02:44,920
and we've already looked at this.

68
00:02:44,920 --> 00:02:46,270
Let's scroll down and have a look.

69
00:02:46,270 --> 00:02:47,990
You can see this one here.

70
00:02:47,990 --> 00:02:49,980
It's very similar to the activity lifecycle

71
00:02:49,980 --> 00:02:52,150
but with a few extra functions.

72
00:02:52,150 --> 00:02:54,110
So this diagram is fine for seeing

73
00:02:54,110 --> 00:02:56,650
the order of the events in our fragments.

74
00:02:56,650 --> 00:02:58,090
But, it doesn't really relate them

75
00:02:58,090 --> 00:03:01,365
to the corresponding activity events.

76
00:03:01,365 --> 00:03:02,198
When we come down here and click on

77
00:03:02,198 --> 00:03:05,823
Handing the Fragment Lifecycle, this one here.

78
00:03:06,940 --> 00:03:09,130
So this shows how the fragment callbacks

79
00:03:09,130 --> 00:03:12,000
fit into the various activity states.

80
00:03:12,000 --> 00:03:13,060
And a little bit further down there's

81
00:03:13,060 --> 00:03:17,340
a Coordinating With the Activity Lifecycle section,

82
00:03:17,340 --> 00:03:20,220
there's a discussion of the extra callbacks

83
00:03:20,220 --> 00:03:22,400
that a fragment actually uses.

84
00:03:22,400 --> 00:03:24,560
And another thing that might be quite useful for you,

85
00:03:24,560 --> 00:03:27,710
there's a complete, a more complete diagram.

86
00:03:27,710 --> 00:03:29,010
Let me paste that link in.

87
00:03:30,000 --> 00:03:30,937
It's on GithHb.

88
00:03:32,006 --> 00:03:34,010
If we scroll down we can see this as well.

89
00:03:34,010 --> 00:03:35,350
Now this is actually quite old

90
00:03:35,350 --> 00:03:37,310
and I can't fit it all on the screen,

91
00:03:37,310 --> 00:03:40,140
but it relates to fragment and activity lifecycle

92
00:03:40,140 --> 00:03:41,750
methods really well.

93
00:03:41,750 --> 00:03:43,830
It also includes the onView Created

94
00:03:43,830 --> 00:03:46,600
and onView Status Restored callbacks

95
00:03:46,600 --> 00:03:48,710
that aren't mentioned in the guide that we were looking at.

96
00:03:48,710 --> 00:03:50,564
So it does try to cover every thing,

97
00:03:50,564 --> 00:03:52,470
and you can see it's really quite comprehensive,

98
00:03:52,470 --> 00:03:54,860
which can be very handy, but as a result,

99
00:03:54,860 --> 00:03:56,980
though it's also quite complicated.

100
00:03:56,980 --> 00:03:59,100
So, I suggest you take the opportunity to bookmark

101
00:03:59,100 --> 00:04:01,340
this page and to use for reference

102
00:04:01,340 --> 00:04:02,610
if you when you need it.

103
00:04:02,610 --> 00:04:03,930
So now that we've seen that, let's go through

104
00:04:03,930 --> 00:04:05,640
the various functions in a slide,

105
00:04:05,640 --> 00:04:07,290
just to keep things a bit simple.

106
00:04:08,660 --> 00:04:11,680
Alright, so starting off, after the activity is created,

107
00:04:11,680 --> 00:04:14,310
it creates any fragment that it contains.

108
00:04:14,310 --> 00:04:17,255
So in our case, that's our MainActivityFragment.

109
00:04:17,255 --> 00:04:19,230
AddEditFragment doesn't get created

110
00:04:19,230 --> 00:04:21,500
because their layout doesn't include it.

111
00:04:21,500 --> 00:04:25,000
We add it in code once the user taps the menu item.

112
00:04:25,000 --> 00:04:27,020
The lifecycle still applies though,

113
00:04:27,020 --> 00:04:29,270
and we'll see how that works in a while.

114
00:04:29,270 --> 00:04:32,040
For now, we'll have a look at each of those functions,

115
00:04:32,040 --> 00:04:34,600
or each of these functions that the Android framework

116
00:04:34,600 --> 00:04:39,600
calls when a fragment is included in an Activity's layout.

117
00:04:39,710 --> 00:04:41,740
So as we discuss each of these functions,

118
00:04:41,740 --> 00:04:43,230
the slides will include a bubble

119
00:04:43,230 --> 00:04:46,497
showing part of the documentation for the function.

120
00:04:46,497 --> 00:04:49,810
And that makes it clearer which function I'm talking about,

121
00:04:49,810 --> 00:04:51,980
and gives a hint of what the documentation

122
00:04:51,980 --> 00:04:53,410
has to say about it.

123
00:04:53,410 --> 00:04:55,210
The fragments onAttach function

124
00:04:55,210 --> 00:04:58,460
gets called first and it's part of the context.

125
00:04:58,460 --> 00:05:00,890
Remember that an activity is a context

126
00:05:00,890 --> 00:05:03,830
so it's a reference to our activity that's posted here.

127
00:05:03,830 --> 00:05:07,580
It's just of type context rather than type activity.

128
00:05:07,580 --> 00:05:09,790
There's also an unattached function that an Activity has

129
00:05:09,790 --> 00:05:12,260
as its argument, but that's been deprecated.

130
00:05:12,260 --> 00:05:15,580
Generally, a context is more useful than an activity.

131
00:05:15,580 --> 00:05:17,640
In fact, if you find yourself trying to refer

132
00:05:17,640 --> 00:05:19,500
to a fragment's activity,

133
00:05:19,500 --> 00:05:21,920
it's likely that you're doing something wrong.

134
00:05:21,920 --> 00:05:23,930
A fragment shouldn't need to know details

135
00:05:23,930 --> 00:05:27,440
about its Activity, other than any interface methods

136
00:05:27,440 --> 00:05:29,310
that the fragment defines.

137
00:05:29,310 --> 00:05:32,120
Between the calls to onAttach and OnDetach,

138
00:05:32,120 --> 00:05:35,700
a fragment has a valid reference to its Activity.

139
00:05:35,700 --> 00:05:38,490
Our AddEditFragment uses that to make sure

140
00:05:38,490 --> 00:05:40,790
it has a listener, when it wants to call

141
00:05:40,790 --> 00:05:42,430
the onSaveClicked function

142
00:05:42,430 --> 00:05:44,970
that its Activities must implement.

143
00:05:44,970 --> 00:05:47,000
So, if you add a fragment in code,

144
00:05:47,000 --> 00:05:49,680
rather that including it in the Activity's layout,

145
00:05:49,680 --> 00:05:52,140
these Lifecycle events will also happen.

146
00:05:52,140 --> 00:05:55,210
They won't be tied to the Activity Lifecycle events.

147
00:05:55,210 --> 00:05:58,620
So what I mean is, you won't see the Activity's onStart

148
00:05:58,620 --> 00:06:01,060
and onResume functions being called, for example,

149
00:06:01,060 --> 00:06:03,260
because the Activity will have already be created

150
00:06:03,260 --> 00:06:05,660
and will be started.

151
00:06:05,660 --> 00:06:08,010
The Fragment will still go through its Lifecycle,

152
00:06:08,010 --> 00:06:10,630
it's just not so closely tied

153
00:06:10,630 --> 00:06:13,950
to the Activity's events in that case.

154
00:06:13,950 --> 00:06:17,600
Right, so moving on, after onAttach, onCreate gets called.

155
00:06:17,600 --> 00:06:20,060
onCreate is conditional.

156
00:06:20,060 --> 00:06:22,810
So, it won't always be called, because it's possible

157
00:06:22,810 --> 00:06:25,520
to prevent a fragment from being destroyed.

158
00:06:25,520 --> 00:06:27,330
We'll come back to that later.

159
00:06:27,330 --> 00:06:29,680
The onCreat function's used to perform

160
00:06:29,680 --> 00:06:33,680
initialization that doesn't involve UI elements.

161
00:06:33,680 --> 00:06:35,700
We shouldn't try to create any widgets,

162
00:06:35,700 --> 00:06:38,040
nor get a reference to them in here.

163
00:06:38,040 --> 00:06:40,460
And that makes sense, because the fragment layout

164
00:06:40,460 --> 00:06:42,600
isn't inflated until the next method's

165
00:06:42,600 --> 00:06:43,800
called the onCreateView.

166
00:06:45,370 --> 00:06:47,510
So onCreateView is where the fragment

167
00:06:47,510 --> 00:06:50,140
creates it's view, if it has one.

168
00:06:50,140 --> 00:06:52,977
It's the fragment's responsibility to inflate its layout

169
00:06:52,977 --> 00:06:56,984
and when Android calls the onCreate View function.

170
00:06:56,984 --> 00:06:58,310
Fragmens don't have to have a view,

171
00:06:58,310 --> 00:07:01,520
in which case this function just returns null.

172
00:07:01,520 --> 00:07:03,160
So that comment from the documentation

173
00:07:03,160 --> 00:07:04,740
is a bit misleading though.

174
00:07:04,740 --> 00:07:07,800
So it implies that onDestroyView doesn't get called

175
00:07:07,800 --> 00:07:10,160
unless your Fragment has returned a view.

176
00:07:10,160 --> 00:07:11,970
That's not the case, as the documentation

177
00:07:11,970 --> 00:07:14,123
for onDestroyView makes clear.

178
00:07:15,100 --> 00:07:16,840
So once the view's been created,

179
00:07:16,840 --> 00:07:20,000
the fragment's view onViewCreated function gets called.

180
00:07:20,000 --> 00:07:22,250
Now that can be useful, if you want to dynamically

181
00:07:22,250 --> 00:07:25,370
alter the fragment's view after creating it.

182
00:07:25,370 --> 00:07:27,590
Generally you'll find that done in onCreateView,

183
00:07:27,590 --> 00:07:30,570
instead after inflating the layout.

184
00:07:30,570 --> 00:07:33,330
Which one you use is down to personal preference, really.

185
00:07:33,330 --> 00:07:35,810
If you had a lot of code in onCreateView,

186
00:07:35,810 --> 00:07:38,470
I'd probably consider moving some of it

187
00:07:38,470 --> 00:07:41,620
to onViewCreated, just to keep things clean.

188
00:07:41,620 --> 00:07:43,830
The documentation, in the bubble on the left,

189
00:07:43,830 --> 00:07:46,490
states that the Fragment's view hierarchy isn't

190
00:07:46,490 --> 00:07:49,050
attached to its parent at this point.

191
00:07:49,050 --> 00:07:50,470
Now, that may seem strange,

192
00:07:50,470 --> 00:07:53,430
because onAttach has already been called.

193
00:07:53,430 --> 00:07:55,270
There's a difference though between the Fragment

194
00:07:55,270 --> 00:07:57,160
being attached to its Activity,

195
00:07:57,160 --> 00:07:59,070
and the Fragment's view being added

196
00:07:59,070 --> 00:08:00,650
to the Activity's layout.

197
00:08:00,650 --> 00:08:03,500
It's the Fragment's view that's being talked about here.

198
00:08:03,500 --> 00:08:04,570
I mentioned that it's possible

199
00:08:04,570 --> 00:08:06,920
to prevent a Fragment from being destroyed

200
00:08:06,920 --> 00:08:08,980
when its Activity gets destroyed.

201
00:08:08,980 --> 00:08:12,340
So if that happens, onCreate won't be called

202
00:08:12,340 --> 00:08:14,490
because the Fragment wasn't destroyed,

203
00:08:14,490 --> 00:08:16,580
there's no need to create it again.

204
00:08:16,580 --> 00:08:18,190
However, if we think about it,

205
00:08:18,190 --> 00:08:21,300
if the activity does get destroyed, then all its widgets

206
00:08:21,300 --> 00:08:25,010
its entire layout, must also then be destroyed.

207
00:08:25,010 --> 00:08:28,530
Our Fragment's widgets appear in the Activity's layout,

208
00:08:28,530 --> 00:08:30,360
so it also follows that our Fragment's

209
00:08:30,360 --> 00:08:32,120
layout must be destroyed.

210
00:08:32,120 --> 00:08:34,799
The Fragment may still esist, but it has

211
00:08:34,799 --> 00:08:36,840
to inflate its layout again

212
00:08:36,840 --> 00:08:40,080
and restore any state that's visible on the UI.

213
00:08:40,080 --> 00:08:41,860
We'll be looking at preventing a Fragment

214
00:08:41,860 --> 00:08:43,559
from being destroyed later.

215
00:08:43,559 --> 00:08:44,840
For now though, just bear in mind

216
00:08:44,840 --> 00:08:46,510
that a Fragment's views have

217
00:08:46,510 --> 00:08:50,070
to be re-created and added to the Activity's layout

218
00:08:50,070 --> 00:08:52,523
whenever the Activity gets destroyed.

219
00:08:53,580 --> 00:08:56,050
Next, we get onActivityCreated.

220
00:08:56,050 --> 00:08:59,340
That's an important callback because before this is called

221
00:08:59,340 --> 00:09:00,880
we can't rely on the activity

222
00:09:00,880 --> 00:09:03,410
being in a fully created state.

223
00:09:03,410 --> 00:09:06,070
Once onActivityCreated has been called,

224
00:09:06,070 --> 00:09:09,740
we know that the Activity's onCreate function has finished.

225
00:09:09,740 --> 00:09:12,390
All these Lifecycle diagrams, even the ones we've created

226
00:09:12,390 --> 00:09:14,660
for these sides, can give the impression

227
00:09:14,660 --> 00:09:16,280
that the Activity's onCreate function

228
00:09:16,280 --> 00:09:19,400
finishes before onAttach gets called.

229
00:09:19,400 --> 00:09:21,190
That's not true and we'll be seeing

230
00:09:21,190 --> 00:09:23,820
proof of that when we run our app soon.

231
00:09:23,820 --> 00:09:26,030
You can't be sure that the Activity's onCreate

232
00:09:26,030 --> 00:09:31,030
function has finished until onActivity gets called.

233
00:09:31,170 --> 00:09:34,533
That can sometimes be important, so keep that in mind.

234
00:09:34,533 --> 00:09:36,520
In the Fragment, each of these functions

235
00:09:36,520 --> 00:09:39,010
will finish before the next one gets called.

236
00:09:39,010 --> 00:09:42,210
But Fragment functions can be called while an Activity

237
00:09:42,210 --> 00:09:44,120
function is still executing.

238
00:09:44,120 --> 00:09:45,749
That's certainly true of the Activity's

239
00:09:45,749 --> 00:09:47,683
onCreate function as we'll see.

240
00:09:48,760 --> 00:09:50,550
onViewStateRestored can be a good place

241
00:09:50,550 --> 00:09:53,980
to make any final changes to the Fragments's UI.

242
00:09:53,980 --> 00:09:57,930
The documentation mentions ticking a checkbox for example.

243
00:09:57,930 --> 00:10:00,590
Depending on the arguments passed to your Fragment,

244
00:10:00,590 --> 00:10:04,040
you may need to display different information on the screen.

245
00:10:04,040 --> 00:10:07,080
Remember that things like EditText and CheckBox widgets

246
00:10:07,080 --> 00:10:09,670
will take care of restoring their own state.

247
00:10:09,670 --> 00:10:11,200
We've seen that a few times,

248
00:10:11,200 --> 00:10:13,400
when we type into an EditText,

249
00:10:13,400 --> 00:10:15,290
then rotate the device.

250
00:10:15,290 --> 00:10:17,180
If for some reason you, wanted to change

251
00:10:17,180 --> 00:10:20,840
the state of an EditText, and not have that change replaced

252
00:10:20,840 --> 00:10:23,510
when the EditText restores its own state,

253
00:10:23,510 --> 00:10:25,770
then this would be the place to do that.

254
00:10:25,770 --> 00:10:27,780
That's probably not a common thing to do,

255
00:10:27,780 --> 00:10:30,400
and the Google diagrams don't even show this function.

256
00:10:30,400 --> 00:10:32,133
But it's there if you need it.

257
00:10:32,970 --> 00:10:35,720
After onViewStateRestored has been called,

258
00:10:35,720 --> 00:10:38,560
the Activity is in the Started state

259
00:10:38,560 --> 00:10:41,010
and its onStart function gets called.

260
00:10:41,010 --> 00:10:44,500
So it's visible to the user, but not yet fully functional.

261
00:10:44,500 --> 00:10:47,770
The fragment then gets its onStart function called.

262
00:10:47,770 --> 00:10:49,600
That seems to be how it works,

263
00:10:49,600 --> 00:10:52,770
but there's nothing in the documentation that guarantees

264
00:10:52,770 --> 00:10:56,253
the Fragment's onStart will be called after the Activity's.

265
00:10:57,250 --> 00:10:58,580
Finally, onResume is called

266
00:10:58,580 --> 00:11:00,260
for the Activity and the Fragment.

267
00:11:00,260 --> 00:11:02,810
They're now running and responding to the user.

268
00:11:02,810 --> 00:11:04,670
You'll notice that the slides show null

269
00:11:04,670 --> 00:11:07,444
being passed into many of these function.

270
00:11:07,444 --> 00:11:08,840
Those are all the functions that receive

271
00:11:08,840 --> 00:11:10,890
a savedInstanceState Bundle,

272
00:11:10,890 --> 00:11:13,030
when the Activity's recreated.

273
00:11:13,030 --> 00:11:14,700
We're showing null because we're showing

274
00:11:14,700 --> 00:11:16,550
the function that are called

275
00:11:16,550 --> 00:11:18,810
when the Activity's first created.

276
00:11:18,810 --> 00:11:21,050
When Android recreates the Activity

277
00:11:21,050 --> 00:11:24,060
and therefore the Fragment, there will be a Bundle available

278
00:11:24,060 --> 00:11:26,295
in each of those functions.

279
00:11:26,295 --> 00:11:28,480
onRestorInstanceState doesn't appear,

280
00:11:28,480 --> 00:11:30,920
because Fragments don't have that function.

281
00:11:30,920 --> 00:11:33,060
As there are five other function that all receive

282
00:11:33,060 --> 00:11:34,960
the savedInstanceState Bundle,

283
00:11:34,960 --> 00:11:37,490
it's probably not surprising that they didn't bother

284
00:11:37,490 --> 00:11:40,278
including that function into a Fragment.

285
00:11:40,278 --> 00:11:41,330
There's one more slide to see,

286
00:11:41,330 --> 00:11:42,610
before we look at the Lifecycle

287
00:11:42,610 --> 00:11:45,810
functions when the Activity's destroyed.

288
00:11:45,810 --> 00:11:47,520
On this slide, I've included a snippet

289
00:11:47,520 --> 00:11:49,790
from the logcat of a running app.

290
00:11:49,790 --> 00:11:51,857
The entries are coloured to match the Activity

291
00:11:51,857 --> 00:11:53,980
and Fragment headings.

292
00:11:53,980 --> 00:11:55,760
This shows two things that I mentioned

293
00:11:55,760 --> 00:11:57,620
in the previous slides.

294
00:11:57,620 --> 00:12:00,000
The first is that the Activity's onCreate function

295
00:12:00,000 --> 00:12:02,230
is still executing while the Fragment

296
00:12:02,230 --> 00:12:04,730
gets its first four function calls.

297
00:12:04,730 --> 00:12:06,780
But after the onViewCreated gets called,

298
00:12:06,780 --> 00:12:09,580
the Activity's still executing its onCreate

299
00:12:09,580 --> 00:12:12,250
you can see the entry that twoPane is false

300
00:12:12,250 --> 00:12:14,743
coming from the Activity's onCreate.

301
00:12:15,790 --> 00:12:19,420
The second is that the Activity's onStart function is called

302
00:12:19,420 --> 00:12:22,060
before the Fragment's onActivityCreated.

303
00:12:22,060 --> 00:12:24,950
The diagrams tend to show the Activity and Fragment onStart

304
00:12:24,950 --> 00:12:28,450
functions next to each other but don't get the impression

305
00:12:28,450 --> 00:12:30,010
that they're called at the same time.

306
00:12:30,010 --> 00:12:34,210
Here, Activity onStart's been moved up to reflect

307
00:12:34,210 --> 00:12:37,020
the position that it gets called, or that it got called,

308
00:12:37,020 --> 00:12:39,710
as shown by those logcat entries.

309
00:12:39,710 --> 00:12:41,690
Alright, so that's a lot to digest

310
00:12:41,690 --> 00:12:43,560
so I'm going to stop the video here.

311
00:12:43,560 --> 00:12:44,760
In the next one, we're gonna go through

312
00:12:44,760 --> 00:12:47,180
the lifecycle functions that are called

313
00:12:47,180 --> 00:12:49,360
when the Activity gets destroyed.

314
00:12:49,360 --> 00:12:51,060
So I'll see you in the next video.

