1
00:00:00,063 --> 00:00:02,278
(bright music)

2
00:00:02,278 --> 00:00:05,132
(typing)

3
00:00:05,132 --> 00:00:08,497
OK, so we've seen the fragment lifecycle diagrams.

4
00:00:08,497 --> 00:00:11,362
In this video, we're gonna log the functions being called

5
00:00:11,362 --> 00:00:14,146
and see how it all plays out in action.

6
00:00:14,146 --> 00:00:15,918
You could get Android to generate

7
00:00:15,918 --> 00:00:18,811
all the stubs for you and then add logging to each one,

8
00:00:18,811 --> 00:00:21,851
just like you did when we discussed the activity lifecycle,

9
00:00:21,851 --> 00:00:23,420
but I'm sure you don't want to watch me

10
00:00:23,420 --> 00:00:24,886
doing that all on video.

11
00:00:24,886 --> 00:00:26,866
So, what I'm going to do is paste in the functions

12
00:00:26,866 --> 00:00:29,163
at the end of Main Activity Fragment.

13
00:00:29,163 --> 00:00:32,598
But firstly, I'm gonna open Main Activity Fragment.

14
00:00:32,598 --> 00:00:34,849
(clicking)

15
00:00:35,986 --> 00:00:40,494
We need to have the usual log tag, so we'll do that first.

16
00:00:40,494 --> 00:00:42,443
(typing)

17
00:00:42,443 --> 00:00:46,610
Private const val TAG equals MainActivityFragment.

18
00:00:50,317 --> 00:00:52,945
Let's also add some logging in the onCreateView function

19
00:00:52,945 --> 00:00:54,381
because we've already written that.

20
00:00:54,381 --> 00:00:57,048
Log dot d parentheses TAG comma,

21
00:00:58,145 --> 00:01:01,562
and it's going to be onCreateView called.

22
00:01:03,545 --> 00:01:05,367
So, I've come down to the...

23
00:01:05,367 --> 00:01:07,823
Just prior to the last right curly brace

24
00:01:07,823 --> 00:01:11,073
and I'm gonna paste in these functions.

25
00:01:12,459 --> 00:01:14,209
Paste them into that.

26
00:01:15,367 --> 00:01:17,982
And just the various lifecycles functions overridden

27
00:01:17,982 --> 00:01:21,129
just with a simple log, you can see there.

28
00:01:21,129 --> 00:01:23,074
I've still got that code in my clipboard,

29
00:01:23,074 --> 00:01:26,157
so I'm going to open AddEditFragment.

30
00:01:27,274 --> 00:01:29,247
I'm gonna paste it in there just to save a bit of time.

31
00:01:29,247 --> 00:01:30,576
Go right down to the bottom there

32
00:01:30,576 --> 00:01:33,041
just prior to the last right curly brace.

33
00:01:33,041 --> 00:01:34,787
Paste it in there.

34
00:01:34,787 --> 00:01:36,759
And, what I'll do firstly is delete this code

35
00:01:36,759 --> 00:01:40,307
that we commented out previously,

36
00:01:40,307 --> 00:01:43,537
but also the fragment has already overridden

37
00:01:43,537 --> 00:01:45,509
some of these functions that I've just pasted in,

38
00:01:45,509 --> 00:01:47,507
so I'm gonna delete the duplicates,

39
00:01:47,507 --> 00:01:49,846
and obviously I'll delete the duplicate that I've just added

40
00:01:49,846 --> 00:01:51,914
and not the original code that we've changed.

41
00:01:51,914 --> 00:01:54,990
So the first one was undetached there that I've just removed

42
00:01:54,990 --> 00:01:56,564
from what was pasted in.

43
00:01:56,564 --> 00:01:59,917
This is onActivityCreated that was also used

44
00:01:59,917 --> 00:02:02,023
but we've also overridden that already

45
00:02:02,023 --> 00:02:05,897
and these last two: onAttach and onCreate,

46
00:02:05,897 --> 00:02:07,227
let's remove those as well.

47
00:02:07,227 --> 00:02:09,338
Because again, we created or overrode

48
00:02:09,338 --> 00:02:12,109
those functions in our code.

49
00:02:12,109 --> 00:02:13,349
Alright so now we're logging all the

50
00:02:13,349 --> 00:02:15,632
lifecycle events in both fragments.

51
00:02:15,632 --> 00:02:18,788
We wanna see how these fit into the activity lifecycle,

52
00:02:18,788 --> 00:02:20,671
so what I'm going to do is paste in

53
00:02:20,671 --> 00:02:23,136
the appropriate activity functions,

54
00:02:23,136 --> 00:02:25,275
lifecycle functions into main activity

55
00:02:25,275 --> 00:02:28,224
before the final right curly brace.

56
00:02:28,224 --> 00:02:30,200
So, I'm gonna open MainActivity

57
00:02:30,200 --> 00:02:33,355
and to the bottom before the last right curly brace,

58
00:02:33,355 --> 00:02:36,216
paste that in there and there's our logging functions

59
00:02:36,216 --> 00:02:38,394
for the various lifecycle functions.

60
00:02:38,394 --> 00:02:39,687
And by the way, you can download the code

61
00:02:39,687 --> 00:02:42,672
to paste this from the resources section of this video.

62
00:02:42,672 --> 00:02:46,783
We've got a text file: FragmentLifecycleCorebacks.txt.

63
00:02:46,783 --> 00:02:49,067
which contains the functions for the fragments

64
00:02:49,067 --> 00:02:51,542
and for our main activity.

65
00:02:51,542 --> 00:02:53,895
Alright so if you remember from the slides,

66
00:02:53,895 --> 00:02:57,289
the activities onCreate function may still be executing

67
00:02:57,289 --> 00:02:59,707
while the fragment callbacks get called.

68
00:02:59,707 --> 00:03:02,414
So, to make that clear in our log I'm gonna add logging

69
00:03:02,414 --> 00:03:04,587
to the end of onCreate.

70
00:03:04,587 --> 00:03:07,703
This is for our MainActivity.

71
00:03:07,703 --> 00:03:09,121
I'm gonna add some logging down here

72
00:03:09,121 --> 00:03:10,704
to that affect so we know.

73
00:03:10,704 --> 00:03:14,871
Log dot d parentheses TAG comma onCreate finished,

74
00:03:19,693 --> 00:03:23,579
and I thought I might add logging for this at the start

75
00:03:23,579 --> 00:03:25,025
but obviously I haven't done that for some reason

76
00:03:25,025 --> 00:03:27,448
so I'm gonna take the opportunity to add some logging

77
00:03:27,448 --> 00:03:30,198
to the onCreate for MainActivity.

78
00:03:31,128 --> 00:03:32,306
And the other thing I'm gonna do,

79
00:03:32,306 --> 00:03:34,629
I'm gonna type inside of log in Twopane

80
00:03:34,629 --> 00:03:36,428
so we know what the value of that is,

81
00:03:36,428 --> 00:03:37,756
because that will prove useful

82
00:03:37,756 --> 00:03:39,473
when we're testing this out.

83
00:03:39,473 --> 00:03:41,896
So log dot d parentheses tag comma,

84
00:03:41,896 --> 00:03:46,063
and we're just gonna put oncreate colon twopane is

85
00:03:47,793 --> 00:03:50,297
dollar m twopane, just the value

86
00:03:50,297 --> 00:03:52,877
of what twopane is set to.

87
00:03:52,877 --> 00:03:54,654
Alright so we can now run the app,

88
00:03:54,654 --> 00:03:56,630
and see these lifecycle events in the logcat.

89
00:03:56,630 --> 00:03:57,637
So what we're gonna do is open

90
00:03:57,637 --> 00:04:00,707
the logcat first, and I'm going to make

91
00:04:00,707 --> 00:04:03,042
sure my emulator is already in landscape mode

92
00:04:03,042 --> 00:04:04,293
which it is now.

93
00:04:04,293 --> 00:04:07,347
So let's actually run this in landscape,

94
00:04:07,347 --> 00:04:10,930
and see the lifecycle events in the logcat.

95
00:04:15,604 --> 00:04:16,721
Can't go back to logcat, I need to

96
00:04:16,721 --> 00:04:19,300
edit out the previous filter.

97
00:04:19,300 --> 00:04:21,690
So I'm gonna remove that, we got

98
00:04:21,690 --> 00:04:24,605
all our code, our logcat entries back.

99
00:04:24,605 --> 00:04:27,438
I'm gonna filter my main activity.

100
00:04:28,734 --> 00:04:30,190
To see any of the entries for the activity

101
00:04:30,190 --> 00:04:32,329
and the fragment main activity.

102
00:04:32,329 --> 00:04:33,752
And as you can see there that seems

103
00:04:33,752 --> 00:04:36,205
to be behaving as we would expect it to do.

104
00:04:36,205 --> 00:04:38,470
So firstly the oncreate function,

105
00:04:38,470 --> 00:04:40,333
activities oncreate gets called,

106
00:04:40,333 --> 00:04:42,679
followed by the fragment events onattach,

107
00:04:42,679 --> 00:04:47,001
oncreate, oncreateview and on viewcreated.

108
00:04:47,001 --> 00:04:48,865
And note that while that was happening

109
00:04:48,865 --> 00:04:50,965
the oncreate was still running

110
00:04:50,965 --> 00:04:53,024
the activities oncreate, then they

111
00:04:53,024 --> 00:04:56,739
can see that there's the twopane debug option there,

112
00:04:56,739 --> 00:04:59,654
that the output there that says twopane is true,

113
00:04:59,654 --> 00:05:01,530
and then we've got oncreate,

114
00:05:01,530 --> 00:05:03,749
I put it on oncreate which should be on oncreate,

115
00:05:03,749 --> 00:05:05,242
we'll fix that shortly.

116
00:05:05,242 --> 00:05:07,334
It's showing that that's been finished.

117
00:05:07,334 --> 00:05:09,271
Then moving on down we've got onstart,

118
00:05:09,271 --> 00:05:11,051
the activity is onstart getting called next.

119
00:05:11,051 --> 00:05:14,380
And the activity is now created and started.

120
00:05:14,380 --> 00:05:16,271
Now that the activity started the fragment

121
00:05:16,271 --> 00:05:17,602
is now as you can see further on,

122
00:05:17,602 --> 00:05:20,435
the fragment onactivity created and onviewstate

123
00:05:20,435 --> 00:05:22,985
was stored, is also called.

124
00:05:22,985 --> 00:05:25,848
Finally the act3v fragment starts and both

125
00:05:25,848 --> 00:05:28,951
objects get an onresume call.

126
00:05:28,951 --> 00:05:30,652
So I'm going to first thing head back

127
00:05:30,652 --> 00:05:32,632
and fix up that top row oncreate that

128
00:05:32,632 --> 00:05:34,812
should not be oncreated.

129
00:05:34,812 --> 00:05:36,790
But then I wanna go back to the logcat.

130
00:05:36,790 --> 00:05:39,402
What I'm gonna do is just put an entry down there, rotating.

131
00:05:39,402 --> 00:05:41,485
(typing)

132
00:05:42,540 --> 00:05:45,043
Then let's go back and rotate this

133
00:05:45,043 --> 00:05:47,376
back into portrait mode now.

134
00:05:48,644 --> 00:05:50,825
And back to our log to check that out.

135
00:05:50,825 --> 00:05:53,093
So as we expected there, the activity is

136
00:05:53,093 --> 00:05:54,715
destroyed and recreated.

137
00:05:54,715 --> 00:05:56,983
Both the activity and the fragment

138
00:05:56,983 --> 00:06:01,725
get on pause, followed in this case by onsaveinstancestate.

139
00:06:01,725 --> 00:06:04,498
Now remember that it isn't guaranteed is called

140
00:06:04,498 --> 00:06:05,790
onsaveinstancestate.

141
00:06:05,790 --> 00:06:08,336
It's not a guarantee to happen before onstop.

142
00:06:08,336 --> 00:06:11,131
It has here but it may or can be called

143
00:06:11,131 --> 00:06:13,324
any time before ondestroy.

144
00:06:13,324 --> 00:06:15,385
Now the remaining events happen

145
00:06:15,385 --> 00:06:17,123
as we've discussed with both the

146
00:06:17,123 --> 00:06:20,792
activity and the fragment being stopped and destroyed.

147
00:06:20,792 --> 00:06:23,743
The teardown finishes when our fragment gets ondetach.

148
00:06:23,743 --> 00:06:25,644
Because Android destroyed the activity,

149
00:06:25,644 --> 00:06:28,001
we get it recreated again.

150
00:06:28,001 --> 00:06:30,296
The events for the activity on the fragment

151
00:06:30,296 --> 00:06:33,048
are the same as when the activity was created initially.

152
00:06:33,048 --> 00:06:34,705
There are two differences here though.

153
00:06:34,705 --> 00:06:37,442
Firstly, twopane is now set to false in our

154
00:06:37,442 --> 00:06:40,676
oncreate method, because we're now in portrait.

155
00:06:40,676 --> 00:06:43,161
Secondly, note that the onrestoreinstancestate

156
00:06:43,161 --> 00:06:46,077
for main activity was called.

157
00:06:46,077 --> 00:06:48,421
Remembe that fragments don't have that function,

158
00:06:48,421 --> 00:06:50,246
you have to use one of the other callbacks

159
00:06:50,246 --> 00:06:54,281
to restorestate, remembering to check for nobundle.

160
00:06:54,281 --> 00:06:56,379
Alright so let's now see what happens when

161
00:06:56,379 --> 00:06:58,764
we switch away from the activities,

162
00:06:58,764 --> 00:07:00,060
I'm going to come down to the end of

163
00:07:00,060 --> 00:07:02,793
the log and put home there.

164
00:07:02,793 --> 00:07:04,376
Go back to our app.

165
00:07:05,620 --> 00:07:07,764
I'm gonna tap the emulator's home button.

166
00:07:07,764 --> 00:07:09,097
Now that's usually the middle button

167
00:07:09,097 --> 00:07:10,947
and it is in this case here.

168
00:07:10,947 --> 00:07:12,282
And sometimes have physical button

169
00:07:12,282 --> 00:07:14,014
in place of the on-screen icon.

170
00:07:14,014 --> 00:07:15,828
We're gonna click on that button now,

171
00:07:15,828 --> 00:07:18,340
and going back to our log.

172
00:07:18,340 --> 00:07:20,663
We can see both the, main activity

173
00:07:20,663 --> 00:07:23,048
and main activity fragment.

174
00:07:23,048 --> 00:07:25,352
So the activity and the fragment are both paused,

175
00:07:25,352 --> 00:07:26,846
But then stopped.

176
00:07:26,846 --> 00:07:28,331
Stop the onstop called as you can see

177
00:07:28,331 --> 00:07:29,550
down in the bottom there.

178
00:07:29,550 --> 00:07:31,331
We also get an onsaveinstancestate

179
00:07:31,331 --> 00:07:33,072
called there as you can see.

180
00:07:33,072 --> 00:07:34,852
As we'll see there is no need restorestate

181
00:07:34,852 --> 00:07:36,997
if the user returns to and activity.

182
00:07:36,997 --> 00:07:40,434
The activity is stopped however, it hasn't been destroyed.

183
00:07:40,434 --> 00:07:42,015
So before returning to the app,

184
00:07:42,015 --> 00:07:44,888
I'm going to add comment returning in the logcat.

185
00:07:44,888 --> 00:07:46,833
(typing)

186
00:07:46,833 --> 00:07:49,068
And now going back to emulator, we wanna use this

187
00:07:49,068 --> 00:07:52,017
square multitasking button over here to the right.

188
00:07:52,017 --> 00:07:53,993
And choose task timer from the list again,

189
00:07:53,993 --> 00:07:57,438
and this the (??) that's currently running, click on that.

190
00:07:57,438 --> 00:08:01,322
And you can see our logcat entry got updated.

191
00:08:01,322 --> 00:08:02,937
Basically the activity and fragment

192
00:08:02,937 --> 00:08:04,710
here restarted and resumed.

193
00:08:04,710 --> 00:08:07,013
There's no callnote to onrestoreinstancestate

194
00:08:07,013 --> 00:08:09,034
for the activity because the activity

195
00:08:09,034 --> 00:08:11,537
was only stopped, it wasn't destroyed,

196
00:08:11,537 --> 00:08:13,913
so therefore no state was lost.

197
00:08:13,913 --> 00:08:15,409
So the final test now, I'm just

198
00:08:15,409 --> 00:08:18,659
going to type back in here, the logcat.

199
00:08:19,535 --> 00:08:22,284
The final test now is to go back to our app.

200
00:08:22,284 --> 00:08:23,889
And use the back button to close the app,

201
00:08:23,889 --> 00:08:26,727
that's this button down here.

202
00:08:26,727 --> 00:08:29,713
We're going back to our log, our logcat again.

203
00:08:29,713 --> 00:08:32,212
We got the onpause, the onstop but this time

204
00:08:32,212 --> 00:08:34,999
also ondestroy being called, finishing with

205
00:08:34,999 --> 00:08:37,506
fragments ondetach down the bottom there.

206
00:08:37,506 --> 00:08:40,333
Note that onsaveinstancestate doesn't get called.

207
00:08:40,333 --> 00:08:43,053
The user, me chose to quit the app, so android

208
00:08:43,053 --> 00:08:46,894
won't attempt to restorestate if the app restarted.

209
00:08:46,894 --> 00:08:49,393
Alright so that's the lifecycle for fragment that's

210
00:08:49,393 --> 00:08:52,106
included in the activities layout.

211
00:08:52,106 --> 00:08:54,817
As we'll see now it's almost exactly the same

212
00:08:54,817 --> 00:08:56,918
when we add a fragment in our code.

213
00:08:56,918 --> 00:08:58,696
So the logcat is gonna be a bit messy if

214
00:08:58,696 --> 00:09:01,491
we leave the entries for main activity fragments showing.

215
00:09:01,491 --> 00:09:03,340
And it's possible to exclude tags

216
00:09:03,340 --> 00:09:04,956
from appearing in the log.

217
00:09:04,956 --> 00:09:06,212
It's not obvious and this is a

218
00:09:06,212 --> 00:09:08,114
good opportunity to show how to do it.

219
00:09:08,114 --> 00:09:09,733
So first here I'm gonna choose the

220
00:09:09,733 --> 00:09:14,650
filter to main activity, then add a pipe, add editfragment.

221
00:09:16,651 --> 00:09:18,268
So the vertical bar, or pipe symbol

222
00:09:18,268 --> 00:09:20,568
between the two tags means (??).

223
00:09:20,568 --> 00:09:22,872
So this will filter ontags, onentries, rather.

224
00:09:22,872 --> 00:09:26,459
Tagged with either mainactivity or add editfragment.

225
00:09:26,459 --> 00:09:28,314
As we've seen the tag mainactivity

226
00:09:28,314 --> 00:09:32,202
we'll also match mainactivityfragment as well.

227
00:09:32,202 --> 00:09:33,742
So at the moment we're in portrait,

228
00:09:33,742 --> 00:09:35,710
so we need to restart our app now to get that running again

229
00:09:35,710 --> 00:09:37,800
so let's do that.

230
00:09:37,800 --> 00:09:39,300
So we did stop it.

231
00:09:41,800 --> 00:09:44,511
Now we're going to tap on the plus icon on the toolbar

232
00:09:44,511 --> 00:09:47,012
to start the addeditfragment, and then we're gonna

233
00:09:47,012 --> 00:09:50,506
look at how to tidy up the logcat.

234
00:09:50,506 --> 00:09:53,183
Okay so the logcat is showing entries for

235
00:09:53,183 --> 00:09:54,482
the activity at the moment.

236
00:09:54,482 --> 00:09:56,343
That's got us both fragments.

237
00:09:56,343 --> 00:09:58,042
As I said that's gonna get bit hard to read

238
00:09:58,042 --> 00:10:00,543
when we rotate the device.

239
00:10:00,543 --> 00:10:03,660
We wanna focus on the activity and addeditfragment,

240
00:10:03,660 --> 00:10:07,654
and should exclude mainactivityfragment from appearing.

241
00:10:07,654 --> 00:10:10,446
So to do that we need to click on any entry

242
00:10:10,446 --> 00:10:13,116
in the log for mainactivityfragment to select it.

243
00:10:13,116 --> 00:10:15,300
So I'm gonna just gonna double click this one here.

244
00:10:15,300 --> 00:10:17,643
With the tag selected right click

245
00:10:17,643 --> 00:10:21,686
and choose the option to fold line like this.

246
00:10:21,686 --> 00:10:23,386
You can see that the dialogue appeared here

247
00:10:23,386 --> 00:10:25,490
containing a list of strings that the logcat

248
00:10:25,490 --> 00:10:29,802
will quote on quote fold, which means not to splay.

249
00:10:29,802 --> 00:10:31,418
Mainactivityfragments been added to the

250
00:10:31,418 --> 00:10:33,558
end of the list as you can see there.

251
00:10:33,558 --> 00:10:36,365
Before I click okay notice the minus button,

252
00:10:36,365 --> 00:10:39,134
we'll use that in minute to unfold these lines.

253
00:10:39,134 --> 00:10:41,539
And that will be read on Linux and Windows

254
00:10:41,539 --> 00:10:43,772
but as you can see it's grey on my mac.

255
00:10:43,772 --> 00:10:46,440
So I'm gonna click okay here.

256
00:10:46,440 --> 00:10:49,114
And notice what's happened, the mainactivityfragment

257
00:10:49,114 --> 00:10:50,653
entry is no longer up here.

258
00:10:50,653 --> 00:10:52,306
So that's a lot clearer now so

259
00:10:52,306 --> 00:10:53,843
let's look at what's happened here.

260
00:10:53,843 --> 00:10:58,006
So I wanna tap the plus icon, the taskedit request function

261
00:10:58,006 --> 00:11:00,992
created a new instance of addeditfragment.

262
00:11:00,992 --> 00:11:03,034
And you can see the taskeditrequest

263
00:11:03,034 --> 00:11:04,823
starting there in the log.

264
00:11:04,823 --> 00:11:06,565
And you can see after that point where the new

265
00:11:06,565 --> 00:11:09,071
instance of editfragment was created, you can see it's

266
00:11:09,071 --> 00:11:11,130
lifecycle functions being called, exactly

267
00:11:11,130 --> 00:11:12,706
the same functions that were called

268
00:11:12,706 --> 00:11:14,720
from mainactivityfragment earlier.

269
00:11:14,720 --> 00:11:16,657
Our fragment goes through the same lifecycle

270
00:11:16,657 --> 00:11:18,919
even when we create it in code.

271
00:11:18,919 --> 00:11:21,099
What you might find surprising though, is that

272
00:11:21,099 --> 00:11:24,769
onactivitycreated is called even though the

273
00:11:24,769 --> 00:11:28,847
activity already existed, that's an important event,

274
00:11:28,847 --> 00:11:30,490
because it let's the fragment know

275
00:11:30,490 --> 00:11:32,192
that it's activity is started.

276
00:11:32,192 --> 00:11:35,308
Android calls this function to let the fragment know that.

277
00:11:35,308 --> 00:11:36,844
So don't think of it as happening

278
00:11:36,844 --> 00:11:38,940
when the activity is created, think of it

279
00:11:38,940 --> 00:11:41,154
as Android letting the fragment know

280
00:11:41,154 --> 00:11:43,539
that it's activity is started.

281
00:11:43,539 --> 00:11:46,322
When you attach a fragment, it'll get this callback

282
00:11:46,322 --> 00:11:47,657
whether you've attached it in the

283
00:11:47,657 --> 00:11:50,042
layout or attached it in code.

284
00:11:50,042 --> 00:11:51,376
Alright so I'm gonna add the comment

285
00:11:51,376 --> 00:11:54,450
rotating here in the logcat.

286
00:11:54,450 --> 00:11:59,200
Then let's go ahead and rotate the device into landscape.

287
00:12:00,750 --> 00:12:03,355
If you come down here, if you take a look at the entry

288
00:12:03,355 --> 00:12:05,698
showing on the screen here we got exactly the same

289
00:12:05,698 --> 00:12:08,685
sequence as we got from mainactivityfragment.

290
00:12:08,685 --> 00:12:10,858
Our fragment was attached to the activity

291
00:12:10,858 --> 00:12:13,358
and there's now no difference between a fragment attached

292
00:12:13,358 --> 00:12:16,553
in code and one attached via the layout.

293
00:12:16,553 --> 00:12:18,213
The activity goes through it's destroy

294
00:12:18,213 --> 00:12:20,236
and recreate lifecycle events and

295
00:12:20,236 --> 00:12:22,581
then the attached fragment follows that.

296
00:12:22,581 --> 00:12:24,189
The last thing to check then is what happens

297
00:12:24,189 --> 00:12:26,966
when we remove the fragment in code.

298
00:12:26,966 --> 00:12:28,060
So I'm gonna add the comment to

299
00:12:28,060 --> 00:12:31,621
the logcat, removing
(typing).

300
00:12:31,621 --> 00:12:33,041
Then I'm gonna go back to the app and

301
00:12:33,041 --> 00:12:34,699
I'm gonna click on save, which will

302
00:12:34,699 --> 00:12:36,949
remove the addeditfragment.

303
00:12:38,188 --> 00:12:40,938
And back to the logcat, although we could see it.

304
00:12:40,938 --> 00:12:42,558
And you can see down there with the log entry

305
00:12:42,558 --> 00:12:43,883
towards the bottom.

306
00:12:43,883 --> 00:12:46,229
Obviously we've got our onsaveclicked called,

307
00:12:46,229 --> 00:12:48,702
removeeditpane, then the fragment goes through the

308
00:12:48,702 --> 00:12:52,187
destroy phase of it's lifecycle onpause, onstop

309
00:12:52,187 --> 00:12:55,770
ondestroyview, then ondestroy and ondetach.

310
00:12:56,796 --> 00:12:58,496
So that's the fragment lifecylcle.

311
00:12:58,496 --> 00:13:00,395
We've seen that a fragment can go through it's

312
00:13:00,395 --> 00:13:04,269
lifecycle independently of the activity it's attached to

313
00:13:04,269 --> 00:13:07,017
if the fragment was attached in code.

314
00:13:07,017 --> 00:13:09,898
Even so the fragments lifecycle is tied to that

315
00:13:09,898 --> 00:13:12,038
of it's activity as we saw when

316
00:13:12,038 --> 00:13:14,501
we rotated the device just now.

317
00:13:14,501 --> 00:13:15,714
We'll be adding dialogues to the app

318
00:13:15,714 --> 00:13:18,301
a bit later in the cause, and you'll see that the dialogue

319
00:13:18,301 --> 00:13:22,383
fragment has the same lifecycle as an ordinary fragment.

320
00:13:22,383 --> 00:13:24,602
For now though that's enough on the lifecycle.

321
00:13:24,602 --> 00:13:26,094
Before I stop this video we better see how

322
00:13:26,094 --> 00:13:28,554
to get those log entries to appear again.

323
00:13:28,554 --> 00:13:31,267
So the quick way if you just want to see a single entry,

324
00:13:31,267 --> 00:13:34,900
is to use the plus button at the start of some of the lines.

325
00:13:34,900 --> 00:13:37,887
So you can tell that a line has been folded,

326
00:13:37,887 --> 00:13:39,423
because you'll have the lines that look like this

327
00:13:39,423 --> 00:13:42,209
on the right hand side here with N interncall

328
00:13:42,209 --> 00:13:44,750
where N is a number one or higher.

329
00:13:44,750 --> 00:13:46,165
So I can come over here and just click

330
00:13:46,165 --> 00:13:49,237
on the plus to the left of these lines.

331
00:13:49,237 --> 00:13:51,951
Now that unexpanded the lines or brings them back

332
00:13:51,951 --> 00:13:54,214
so you can actually see them again.

333
00:13:54,214 --> 00:13:55,998
So to complete removing the folding,

334
00:13:55,998 --> 00:13:57,659
select something by right clicking again,

335
00:13:57,659 --> 00:14:01,013
so I'm just going to select the mainactivityfragment again,

336
00:14:01,013 --> 00:14:05,063
right click, and click on fold lines like this again.

337
00:14:05,063 --> 00:14:07,119
So to completely remove the unfolding,

338
00:14:07,119 --> 00:14:09,751
select something and right click it again as you saw me do.

339
00:14:09,751 --> 00:14:11,709
It doesn't matter what you select, although I prefer

340
00:14:11,709 --> 00:14:14,714
to select the same tag that I folded.

341
00:14:14,714 --> 00:14:17,224
Alright so now we got the same entry, mainactivityfragment

342
00:14:17,224 --> 00:14:20,329
appearing twice now in the dialogue, if you selected some

343
00:14:20,329 --> 00:14:23,647
other text you'll see that instead of one of these entries.

344
00:14:23,647 --> 00:14:26,833
So select each one in turn, and use the minus button to

345
00:14:26,833 --> 00:14:29,740
delete it from the list, so I gotta do that twice.

346
00:14:29,740 --> 00:14:32,489
We've now removed that from the list of entries to fold.

347
00:14:32,489 --> 00:14:34,593
Click on okay and you can see that they're all now

348
00:14:34,593 --> 00:14:38,430
appearing again as I would have normally done.

349
00:14:38,430 --> 00:14:40,896
Alright so that's the folding now being removed, and

350
00:14:40,896 --> 00:14:42,231
we've got our full list of entries

351
00:14:42,231 --> 00:14:43,849
that match our filtered text.

352
00:14:43,849 --> 00:14:46,277
Let's end the video here now and in the next one we're gonna

353
00:14:46,277 --> 00:14:49,826
add support for the back and up buttons to allow the users

354
00:14:49,826 --> 00:14:52,418
to return to the main activity.

355
00:14:52,418 --> 00:14:54,873
So I'll see you in the next video.

