1
00:00:00,150 --> 00:00:06,150
Hire everyone in this theater we're going to go ahead and create another Android application.

2
00:00:06,150 --> 00:00:07,160
So just click on this.

3
00:00:07,170 --> 00:00:09,560
Start in your Android studio project.

4
00:00:09,630 --> 00:00:22,510
So here for the application name just type in an app 51 dash Android lifecycle OK life cycle and then

5
00:00:22,640 --> 00:00:24,480
click Next choose.

6
00:00:24,520 --> 00:00:30,370
AP 16 Android 4.1 Jelly Bean for minimum STK phone and tablet.

7
00:00:30,400 --> 00:00:30,890
OK.

8
00:00:30,970 --> 00:00:35,170
Next on here choose Blanche activity next.

9
00:00:35,500 --> 00:00:36,970
And then click can finish.

10
00:00:37,090 --> 00:00:37,820
OK.

11
00:00:38,020 --> 00:00:43,960
Now let's actually select this hello world takes you here and then present the key on your keyboard

12
00:00:44,320 --> 00:00:46,450
and then it's actually go inside the stress folder.

13
00:00:46,500 --> 00:00:52,870
Lay out activity on the line make that example and then select is faluting action button and then press

14
00:00:52,870 --> 00:00:54,200
and delete key on your keyboard.

15
00:00:54,200 --> 00:01:00,580
OK so now let's actually go back and say this main activity the double file here and then let's actually

16
00:01:00,580 --> 00:01:06,850
delete these lines of code that are related to the Options menu and then deletes these lines of code

17
00:01:06,850 --> 00:01:09,940
that are related to the floating action button.

18
00:01:09,940 --> 00:01:15,050
Now I want to actually put in some more efforts inside inside of this class.

19
00:01:15,070 --> 00:01:15,590
OK.

20
00:01:15,880 --> 00:01:19,690
So as you can see this is the uncreate method.

21
00:01:19,720 --> 00:01:20,460
OK.

22
00:01:20,620 --> 00:01:23,840
This is actually one of the Android lifecycle efforts.

23
00:01:23,890 --> 00:01:29,070
And now I want to add the other lifecycle methods inside this main activity class.

24
00:01:29,080 --> 00:01:29,680
OK.

25
00:01:29,830 --> 00:01:36,370
So first of all inside these are made I create if you want to actually create a toast in order to show

26
00:01:36,370 --> 00:01:37,600
the user a message.

27
00:01:37,660 --> 00:01:38,850
When my application runs.

28
00:01:38,860 --> 00:01:39,290
OK.

29
00:01:39,430 --> 00:01:44,600
So first of all in order to create a toast I need to refer to the name of the toaster class.

30
00:01:44,650 --> 00:01:46,300
Ok toast.

31
00:01:46,350 --> 00:01:46,820
OK.

32
00:01:46,900 --> 00:01:49,300
That makes text.

33
00:01:49,360 --> 00:01:52,850
So as you can see this cross-class has an effect.

34
00:01:52,900 --> 00:01:58,570
A static method actually that we can call on this class or keep this in if it is a class my faith so

35
00:01:58,570 --> 00:02:01,110
that we can call this method on this class.

36
00:02:01,120 --> 00:02:01,660
OK.

37
00:02:01,870 --> 00:02:06,070
And inside of the apprentice's of this Meffert we need to specify free arguments.

38
00:02:06,100 --> 00:02:11,160
Ok so here for the first argument we need to specify the context.

39
00:02:11,170 --> 00:02:11,610
OK.

40
00:02:11,710 --> 00:02:15,530
So for the context context we can actually refer to that to this class.

41
00:02:15,560 --> 00:02:17,010
OK so this.

42
00:02:17,060 --> 00:02:18,350
OK comma.

43
00:02:18,650 --> 00:02:23,050
And now I need to specify the text that you want to show to show the user.

44
00:02:23,050 --> 00:02:28,490
OK so I just need to put in two double quotes and instead of double quotes I can just type in but the

45
00:02:28,660 --> 00:02:41,810
UN create Meffert is called ok and comma and then I need to actually specify the duration of my message

46
00:02:41,810 --> 00:02:46,670
or cater to change the direction of the message that is being shown to the user.

47
00:02:46,670 --> 00:02:48,500
So here I can just type in TOSed

48
00:02:51,140 --> 00:02:53,530
dot land line.

49
00:02:53,880 --> 00:02:54,440
OK.

50
00:02:54,700 --> 00:02:59,330
And now I need to actually call them if it's show on this method.

51
00:02:59,350 --> 00:02:59,630
OK.

52
00:02:59,780 --> 00:03:04,600
Undismayed text Meffert so that show.

53
00:03:04,650 --> 00:03:07,910
OK so now it's going to actually show this message message to the user.

54
00:03:07,930 --> 00:03:08,660
OK.

55
00:03:09,010 --> 00:03:12,790
So let's actually add the other benefits here.

56
00:03:13,030 --> 00:03:15,710
After the end in Kerley place of this uncreate Moffet.

57
00:03:15,820 --> 00:03:19,500
Now I want to add the other lifecycle benefits to this class.

58
00:03:19,510 --> 00:03:23,400
So the other lifecycle Mefford is the Meffert on start.

59
00:03:23,440 --> 00:03:27,790
OK so I'm going to paste this method here and then I'm going to explain to you what's going on here.

60
00:03:27,820 --> 00:03:30,080
So as you can see here this is the method on starts.

61
00:03:30,190 --> 00:03:30,880
OK.

62
00:03:31,240 --> 00:03:37,270
And as you can see the return type of the sign if it is void and the name of this if it is on start.

63
00:03:37,330 --> 00:03:37,800
OK.

64
00:03:37,810 --> 00:03:43,760
And as you can see here the access modifier of this method is protected and this means that this method

65
00:03:43,780 --> 00:03:49,180
is only visible to the class that this it is actually created and there are some classes that inherit

66
00:03:49,390 --> 00:03:50,560
from this class.

67
00:03:50,680 --> 00:03:51,350
OK.

68
00:03:51,710 --> 00:03:56,760
And as you can see here in say that this May 5th we are calling the super that Arne's and starts Moffit.

69
00:03:56,930 --> 00:04:01,130
OK as we did for this uncreate benefit super that uncreate.

70
00:04:01,600 --> 00:04:08,310
And now as you can see we actually created this toast here talks that make text.

71
00:04:08,410 --> 00:04:12,340
This this is for the context of this application.

72
00:04:12,820 --> 00:04:19,570
OK if you are referring to this class main activity that that is actually controlling the current activity

73
00:04:19,600 --> 00:04:20,930
underline may not examine.

74
00:04:21,060 --> 00:04:21,750
OK.

75
00:04:22,210 --> 00:04:26,700
And here this is the text of our toast and starts Meffert is called.

76
00:04:26,950 --> 00:04:27,490
OK.

77
00:04:27,760 --> 00:04:29,420
And here the duration of the text.

78
00:04:29,440 --> 00:04:30,010
OK.

79
00:04:30,250 --> 00:04:33,010
To toast that line like that.

80
00:04:33,010 --> 00:04:33,630
Sure.

81
00:04:33,910 --> 00:04:34,400
OK.

82
00:04:34,420 --> 00:04:37,870
And here we are actually showing that message to the user.

83
00:04:37,870 --> 00:04:40,260
Now let's actually look at the other lifecycle Mefford.

84
00:04:40,360 --> 00:04:45,010
So here I'm going to paste this method here and then I'm going to explain to you what's going on here.

85
00:04:45,010 --> 00:04:45,800
OK.

86
00:04:45,970 --> 00:04:49,780
So as you can see here the other it is always do OK.

87
00:04:49,810 --> 00:04:53,760
So for the first time that this application is actually going to start.

88
00:04:53,770 --> 00:04:57,330
So the first method that is going to be called is this method.

89
00:04:57,370 --> 00:04:58,130
Uncreate.

90
00:04:58,240 --> 00:04:58,660
OK.

91
00:04:58,810 --> 00:05:01,360
And then it's going to show this message to the user.

92
00:05:01,720 --> 00:05:06,430
And the second half that this is going to be called is this unstopped method.

93
00:05:06,490 --> 00:05:07,240
OK.

94
00:05:07,690 --> 00:05:12,310
And this message is going to be shown to the user and the first method that is going to be called is

95
00:05:12,310 --> 00:05:13,590
this on resume Meffert.

96
00:05:13,600 --> 00:05:20,750
OK as you can see and here it says TOSed that make text this and resume if it is called toast.

97
00:05:20,770 --> 00:05:22,260
That red flag does show.

98
00:05:22,330 --> 00:05:28,020
OK so now let's actually run our project and see what happens.

99
00:05:28,030 --> 00:05:28,640
OK.

100
00:05:31,510 --> 00:05:38,100
So as you can see the uncreate method is called the on start method is called and then the resume if

101
00:05:38,100 --> 00:05:39,430
it is actually called.

102
00:05:39,580 --> 00:05:40,230
OK.

103
00:05:41,020 --> 00:05:45,290
So now let's actually call the other Democrats here it's actually create.

104
00:05:45,330 --> 00:05:46,190
All right.

105
00:05:46,240 --> 00:05:49,690
The other lifecycle fits inside of this class.

106
00:05:50,010 --> 00:05:50,230
OK.

107
00:05:50,230 --> 00:05:52,700
Inside of this main activity class.

108
00:05:52,760 --> 00:05:58,850
So the other lifecycle Meffert that you want to put inside of this class is the unpause may.

109
00:05:58,960 --> 00:06:01,720
So as you can see here this is the unposed Meffert.

110
00:06:01,930 --> 00:06:03,060
OK.

111
00:06:03,220 --> 00:06:08,770
And here as you can see I'm going to actually show this message to the user when this application is

112
00:06:08,770 --> 00:06:10,500
actually on the unpassed state.

113
00:06:10,510 --> 00:06:11,110
OK.

114
00:06:11,410 --> 00:06:17,000
And now I want to actually override the other lifecycle effect here inside of this class.

115
00:06:17,110 --> 00:06:22,060
So now I'm going actually pasting the other lifecycle effect inside of this class.

116
00:06:22,120 --> 00:06:22,540
OK.

117
00:06:22,660 --> 00:06:27,650
So as you can see here the other lifecycle method is these unrestored Mefford.

118
00:06:27,900 --> 00:06:28,490
OK.

119
00:06:28,780 --> 00:06:32,800
And here I'm going to actually show this message to the user and it is unrestored.

120
00:06:32,850 --> 00:06:34,080
It is called.

121
00:06:34,450 --> 00:06:35,380
OK.

122
00:06:35,870 --> 00:06:41,080
And now let's actually put in the other lifecycle my it inside of this class.

123
00:06:41,230 --> 00:06:44,940
So the other lifecycle Mefford is undestroyed Meffert.

124
00:06:44,950 --> 00:06:45,490
OK.

125
00:06:45,640 --> 00:06:49,150
So this method is going to be called Venda application.

126
00:06:49,160 --> 00:06:57,490
Vendy activity is actually completely destroyed and we cannot and the activity is not stored in memory

127
00:06:57,490 --> 00:06:58,130
anymore.

128
00:06:58,350 --> 00:06:58,770
OK.

129
00:06:58,870 --> 00:07:02,780
So some of it undestroyed is going to be called in that specific time.

130
00:07:02,950 --> 00:07:07,230
And this message on the stream if it is called is going to be shown to the user.

131
00:07:07,270 --> 00:07:11,880
OK so now let's actually run our project and see what happens.

132
00:07:11,920 --> 00:07:12,780
OK.

133
00:07:13,570 --> 00:07:16,240
So as you can see the uncreate Mfat is called.

134
00:07:16,330 --> 00:07:16,780
OK.

135
00:07:16,930 --> 00:07:22,510
And then the unstarted if it is called here and then the on resume if it is called.

136
00:07:22,620 --> 00:07:26,400
Ok so now our application is actually under our resumes.

137
00:07:26,410 --> 00:07:26,950
OK.

138
00:07:27,160 --> 00:07:31,240
So now if I actually click on dispatch button let's see what happens.

139
00:07:31,300 --> 00:07:36,470
So now let's actually click on dispatch button here and let's see what happens.

140
00:07:36,490 --> 00:07:37,140
OK.

141
00:07:37,450 --> 00:07:39,780
So as you can see here the opposite effect is called.

142
00:07:39,940 --> 00:07:42,090
And then the undestroyed method is called.

143
00:07:42,100 --> 00:07:47,680
So now the app our application is actually completely destroyed and it is not stored in memory anymore.

144
00:07:47,920 --> 00:07:54,700
OK so now I can actually go back to our application I want to start my application again.

145
00:07:54,730 --> 00:08:02,030
So here inside this main menu I can actually search for my application as you can see.

146
00:08:02,350 --> 00:08:05,860
This is our app effective on Android lifecycle.

147
00:08:06,010 --> 00:08:10,930
So the uncreate my is called the On-Star my faith is called.

148
00:08:11,730 --> 00:08:13,680
And then the resume if it is caught.

149
00:08:13,680 --> 00:08:16,770
So now our application is in the andr's state.

150
00:08:16,770 --> 00:08:17,310
OK.

151
00:08:17,400 --> 00:08:20,080
So here I want to actually to go to the home.

152
00:08:20,130 --> 00:08:20,770
OK.

153
00:08:20,910 --> 00:08:23,660
So the home screen of my emulator.

154
00:08:23,760 --> 00:08:30,390
So I just need to click on this little circle here as you can see and as you can see the on plasma if

155
00:08:30,390 --> 00:08:31,360
it is called.

156
00:08:31,780 --> 00:08:36,100
And now our application is actually on the unpause state.

157
00:08:36,400 --> 00:08:36,990
OK.

158
00:08:37,050 --> 00:08:40,470
Now if you want to go back to my application let's see what happens here.

159
00:08:40,530 --> 00:08:47,490
As you can see if I click on this little square here now I can see the other applications up in the

160
00:08:47,490 --> 00:08:48,150
background.

161
00:08:48,150 --> 00:08:48,620
OK.

162
00:08:48,720 --> 00:08:51,020
So this application is actually in the background.

163
00:08:51,300 --> 00:08:54,810
And now if I selected unrestored MURPHY It is called.

164
00:08:55,030 --> 00:09:01,350
OK on start MFL this card and then the Andrew is you Mefford is going to be called.

165
00:09:01,350 --> 00:09:03,990
So again our application is on.

166
00:09:04,250 --> 00:09:05,710
Is your state.

167
00:09:05,900 --> 00:09:06,960
OK.

168
00:09:07,500 --> 00:09:09,270
So hopefully that makes sense.

169
00:09:09,270 --> 00:09:14,940
And if you have any questions about Android lifecycle please post the discussion in the course and I'll

170
00:09:14,970 --> 00:09:17,750
do my best to answer all of your questions.

171
00:09:17,760 --> 00:09:21,120
Thank you very much for watching and I'll see you in the next year Tauriel.

