1
00:00:00,390 --> 00:00:05,260
First of all I actually created an object of type intent as you can see here.

2
00:00:05,430 --> 00:00:08,570
So intent intent knew intent and here.

3
00:00:08,660 --> 00:00:12,830
And when I actually go from this main activity class to this main activity class.

4
00:00:12,990 --> 00:00:17,660
So when the user clicks on the notification I want to actually move to this main activity.

5
00:00:17,790 --> 00:00:18,550
OK.

6
00:00:18,780 --> 00:00:23,940
I can actually specify other activities but for this application I just wanted to show you how to use

7
00:00:24,250 --> 00:00:28,000
notifications and how to create and manipulate notifications.

8
00:00:28,080 --> 00:00:29,850
So it is going to be a little bit simple.

9
00:00:30,030 --> 00:00:35,370
So just a new intent and I want to actually move to this main activity class so here as you can see

10
00:00:35,370 --> 00:00:39,200
for the first argument I specified this May 9th main activity that this.

11
00:00:39,210 --> 00:00:44,860
So this is going to be the context and for the second argument I actually specified main activity that

12
00:00:44,880 --> 00:00:45,610
class.

13
00:00:45,630 --> 00:00:49,040
So this means that you want to move to this main activity class here.

14
00:00:49,170 --> 00:00:49,880
OK.

15
00:00:50,230 --> 00:00:52,210
And in line free.

16
00:00:52,320 --> 00:00:55,160
I actually created an object of type pain.

17
00:00:55,230 --> 00:00:56,020
Intent.

18
00:00:56,240 --> 00:00:56,670
OK.

19
00:00:56,700 --> 00:01:02,640
So let's actually open our web browser and let's actually go to Android documentation and see what is

20
00:01:02,640 --> 00:01:04,290
this pending intent.

21
00:01:04,290 --> 00:01:12,400
So now let's actually open our browser and here in the search bar just typing here pending intent.

22
00:01:13,050 --> 00:01:18,930
And here as you can see we have this pending intent inside this android that app package just select

23
00:01:18,930 --> 00:01:21,280
it and click on it.

24
00:01:21,300 --> 00:01:24,000
So now we are actually guided to this page.

25
00:01:24,180 --> 00:01:27,650
So as you can see here we have these pending intent class.

26
00:01:27,720 --> 00:01:31,870
This is actually a public class final class pending intent.

27
00:01:32,160 --> 00:01:32,750
OK.

28
00:01:32,850 --> 00:01:35,060
So now here is our description.

29
00:01:35,140 --> 00:01:41,910
So a description of an intent and target action to perform with it in instances of this class are created

30
00:01:41,910 --> 00:01:43,390
with good activity.

31
00:01:43,410 --> 00:01:46,780
This is actually an effort that we are going to use for our notification.

32
00:01:46,800 --> 00:01:52,980
So here as you can see it says by giving appending intent to another application you are granted get

33
00:01:53,210 --> 00:02:00,340
the right to perform the operation you have specified as if the other application was yourself.

34
00:02:00,630 --> 00:02:01,210
OK.

35
00:02:01,350 --> 00:02:07,590
With the same permissions and identity as such you should be careful about how you build the dependent

36
00:02:07,650 --> 00:02:15,210
intent almost always the base intent you supply should have the component name explicitly set to one

37
00:02:15,210 --> 00:02:22,710
of your own components to ensure it is ultimately sent there and nowhere else are pending intent itself

38
00:02:22,740 --> 00:02:29,640
is simply a reference to a token made maintained by the system described me in the original data used

39
00:02:29,670 --> 00:02:30,570
to retrieve it.

40
00:02:30,570 --> 00:02:37,740
This means that even if it's own applications process is kid is killed depended intent itself will remain

41
00:02:37,740 --> 00:02:41,530
usable from other processes that have been given it.

42
00:02:42,060 --> 00:02:48,710
If they create an application Leader Reid retrieves the same kind of paper and an intent same operations

43
00:02:48,710 --> 00:02:50,040
same intent action.

44
00:02:50,110 --> 00:02:56,790
Or categories and components and same flags it will receive appending intent representing the same token

45
00:02:56,790 --> 00:03:02,030
if it's if that is still valid and you can call cancel to remove it.

46
00:03:02,280 --> 00:03:05,650
So now let's actually look at some of the merits of this class.

47
00:03:05,650 --> 00:03:12,720
So as you can see here these are the public Moffats can sell the scrap contents equals good activities.

48
00:03:12,780 --> 00:03:14,940
And we have some of the effects of this class.

49
00:03:15,060 --> 00:03:17,240
So let's go back to our Andrex studio here.

50
00:03:17,240 --> 00:03:23,370
I want to specify that when the user clicks on the notification I want to update the current main activity.

51
00:03:23,590 --> 00:03:29,920
OK I want to actually guide the user to the current activity so I need to create this intent.

52
00:03:30,020 --> 00:03:36,840
OK so pending intent that gets activity this is actually a method that is inside of this class main

53
00:03:36,840 --> 00:03:42,630
activity that this sort of first argument is going to be the context main activity that this the second

54
00:03:42,630 --> 00:03:44,520
argument is going to be the request code.

55
00:03:44,670 --> 00:03:45,190
OK.

56
00:03:45,240 --> 00:03:51,600
That is that it's going to actually specify that this notification is actually specific only to this

57
00:03:51,870 --> 00:03:52,380
activity.

58
00:03:52,380 --> 00:03:52,900
OK.

59
00:03:53,130 --> 00:03:59,760
So we can have multiple notifications in that application so we use this request code to identify are

60
00:04:00,030 --> 00:04:05,100
not notifications so this notification has this request code number zero.

61
00:04:05,240 --> 00:04:05,860
OK.

62
00:04:06,060 --> 00:04:07,030
And the intent.

63
00:04:07,080 --> 00:04:08,790
The argument is going to be the intent.

64
00:04:08,800 --> 00:04:14,210
So to actually if we want to actually move to this activity to this main activity so I put I actually

65
00:04:14,220 --> 00:04:15,660
assigned this intent here.

66
00:04:15,930 --> 00:04:20,800
And for the last argument we need to put the spent in intent that flag updates colorant.

67
00:04:20,880 --> 00:04:26,040
So let's actually go back to what Android documentation again and here let's actually search for.

68
00:04:26,040 --> 00:04:29,990
So here I just need to hold the Comanche and then person F key on my keyboard.

69
00:04:30,000 --> 00:04:34,680
So if you are using a Windows machine you need to hold the control key and then present their key on

70
00:04:34,680 --> 00:04:44,220
your keyboard and then here I just need to type in Flag updates current update current.

71
00:04:44,280 --> 00:04:49,250
I just need to click on this flight update calendar here and as you can see we have these flight updates

72
00:04:49,260 --> 00:04:57,030
current and it says that a flag indicating that if they described pending intent already exists then

73
00:04:57,030 --> 00:05:04,220
keep it but replace its extra state of it in this new intent OK flag indicating.

74
00:05:04,300 --> 00:05:05,770
So let me actually read it again.

75
00:05:05,900 --> 00:05:13,320
Flag indicating that if they describe the painting intent already exists then keep hit but replace it's

76
00:05:13,490 --> 00:05:18,280
extra state with what is in this new intent for use with get activity.

77
00:05:18,290 --> 00:05:22,640
So as you can see here we are using these activities that activity Meffert here.

78
00:05:22,820 --> 00:05:29,300
This can be used if you are creating intense but only Dijkstra's change and don't care that any entities

79
00:05:29,540 --> 00:05:36,440
that received your previous pending intent will be able to learn it with your new extras even if they

80
00:05:36,440 --> 00:05:38,290
are not explicitly given to it.

81
00:05:38,540 --> 00:05:44,910
So here because we want to actually only move to our main activity again we can actually use this a

82
00:05:44,960 --> 00:05:50,260
flash update current and we can actually update some information in our activity.

83
00:05:50,360 --> 00:05:50,680
Okay.

84
00:05:50,690 --> 00:05:53,380
And that's the purpose of this flight update current.

85
00:05:53,510 --> 00:05:54,040
OK.

86
00:05:54,110 --> 00:05:59,590
He's going to actually keep the same intent as you can see here depending.

87
00:05:59,630 --> 00:06:00,910
Intent already exists.

88
00:06:00,950 --> 00:06:05,210
Ok then it's going to actually keep it but replace it throw it data.

89
00:06:05,330 --> 00:06:05,840
OK.

90
00:06:05,840 --> 00:06:09,410
So we may have some extra data but this can actually replace those data.

91
00:06:09,410 --> 00:06:10,020
OK.

92
00:06:10,340 --> 00:06:16,850
So if we use this flag update current and in line of 57 as you can see I called this builder that said

93
00:06:16,850 --> 00:06:19,950
content intent pending intent.

94
00:06:20,540 --> 00:06:20,930
OK.

95
00:06:21,020 --> 00:06:25,770
So here I am actually setting the content intent on this up here.

96
00:06:25,860 --> 00:06:30,430
With that said content intent and then intent I passed is pending but opinion intent.

97
00:06:30,440 --> 00:06:33,530
Object to the Smurfette and in line 59.

98
00:06:33,640 --> 00:06:37,050
I am actually creating an object of type notification manager.

99
00:06:37,090 --> 00:06:39,110
OK so notification manager.

100
00:06:39,300 --> 00:06:42,350
And then the name of this object is notification manager.

101
00:06:42,500 --> 00:06:46,420
And here I am casting this object to a notification manager object.

102
00:06:46,520 --> 00:06:50,590
And here I am calling this method get system service notification service.

103
00:06:50,600 --> 00:06:53,750
So we need to actually get the system serviced notification service.

104
00:06:53,750 --> 00:06:57,950
It is very important in order to actually create a notification in our application.

105
00:06:57,950 --> 00:06:58,460
OK.

106
00:06:58,790 --> 00:07:00,130
So notification service.

107
00:07:00,140 --> 00:07:05,390
So I am actually getting this notification service and I am assigning to this notification manager that's

108
00:07:05,390 --> 00:07:07,410
value and in length 60.

109
00:07:07,410 --> 00:07:10,430
I am calling this notification manager that notify.

110
00:07:10,550 --> 00:07:11,120
OK.

111
00:07:11,180 --> 00:07:13,660
And the first argument is going to be detach.

112
00:07:13,880 --> 00:07:15,910
So I called dispatch notify.

113
00:07:16,010 --> 00:07:18,020
OK you can call it whatever you want.

114
00:07:18,050 --> 00:07:24,110
And the second argument is client is going to be the ID of this notification manager.

115
00:07:24,110 --> 00:07:26,670
So I assign this value one hundred twenty three.

116
00:07:26,750 --> 00:07:27,620
One two three.

117
00:07:28,130 --> 00:07:30,190
And you can assign whatever value you want.

118
00:07:30,200 --> 00:07:31,870
So it is going to be an integer value.

119
00:07:31,880 --> 00:07:36,770
OK this is going to be the ID and the Fred argument is going to be the builder that built.

120
00:07:36,980 --> 00:07:42,250
So I referred to the name of this object builder and I called the Smurfit build.

121
00:07:42,290 --> 00:07:48,950
So now we need to actually Conti's Schoener to vacation Meffert in our unclick if it here.

122
00:07:48,950 --> 00:07:52,980
So here I can just type in show notification.

123
00:07:53,000 --> 00:07:55,820
So now let's run our project and see what happens.

124
00:07:55,820 --> 00:08:00,800
So now as you can see here our application is running on this emulator here.

125
00:08:00,800 --> 00:08:07,640
So now for the title of the notification I can just type in title and for the text I can just type in

126
00:08:07,640 --> 00:08:08,100
text.

127
00:08:08,120 --> 00:08:08,870
OK.

128
00:08:08,870 --> 00:08:10,740
So let's actually click on this button here.

129
00:08:11,060 --> 00:08:14,050
Notify me so now as you can see we have a notification.

130
00:08:14,060 --> 00:08:16,830
So let's actually right here.

131
00:08:17,270 --> 00:08:21,980
And as you can see we have this notification and the title is title and the text is text.

132
00:08:22,100 --> 00:08:23,390
And we have this icon here.

133
00:08:23,390 --> 00:08:23,920
OK.

134
00:08:24,110 --> 00:08:27,330
So let's see if we actually click on this notification here.

135
00:08:27,380 --> 00:08:30,050
Now we are guided again to this activity.

136
00:08:30,230 --> 00:08:36,260
And as you can see it here the the data is actually updated here as you can see because we are actually

137
00:08:36,350 --> 00:08:38,580
moving again to this activity.

138
00:08:38,630 --> 00:08:41,380
So it's going to call the uncreate method here again.

139
00:08:41,410 --> 00:08:43,260
So now as you can see the data is gone.

140
00:08:43,430 --> 00:08:44,270
OK.

141
00:08:44,660 --> 00:08:46,310
So hopefully that makes sense.

142
00:08:46,310 --> 00:08:51,560
So now as you can see if I actually click on this notify me again here without assigning a value to

143
00:08:51,560 --> 00:08:53,030
these text fields.

144
00:08:53,030 --> 00:08:58,240
So if you actually look at the notifications here now as you can see again it's actually created our

145
00:08:58,550 --> 00:09:01,930
notification here for me but without the title and the text.

146
00:09:02,060 --> 00:09:08,210
So I don't want to allow the application to create a notification without the title and the text.

147
00:09:08,240 --> 00:09:10,650
So here inside is main activity class.

148
00:09:10,790 --> 00:09:11,940
Inside is Uncle Meffert.

149
00:09:11,950 --> 00:09:22,160
I can actually create an if statement so if it's the content title that get text that to a strange dot

150
00:09:22,220 --> 00:09:28,190
matches and here inside the practices of this matches here matches Mefford I just need to put two double

151
00:09:28,190 --> 00:09:34,250
quotes and this means that if the value of this text here as you can see if the value of this Edhi text

152
00:09:34,490 --> 00:09:35,770
is actually empty.

153
00:09:35,960 --> 00:09:36,680
OK.

154
00:09:36,920 --> 00:09:45,310
And here let me actually create an all logical operator or EDT a content text.

155
00:09:45,320 --> 00:09:49,700
This time I referred to that with this name in it its content text.

156
00:09:49,850 --> 00:09:57,180
Ok that's good text that too strange that matches.

157
00:09:57,720 --> 00:09:58,280
OK.

158
00:09:58,460 --> 00:10:05,710
And here again I need to two double quotes here without assigning any value to these inside these are

159
00:10:05,750 --> 00:10:06,600
two double quotes.

160
00:10:06,640 --> 00:10:11,250
So I just need to open and close this statement by using these curly braces as you can see here.

161
00:10:11,500 --> 00:10:15,170
So let me create a new line here so that you can see this.

162
00:10:15,370 --> 00:10:19,960
This piece of code he had better and now I can just type in return.

163
00:10:20,680 --> 00:10:24,860
And this return here means do not execute this method anymore.

164
00:10:24,870 --> 00:10:30,080
This unclear if it anymore is going to actually break out of the Smurfit break out of the Smurfit.

165
00:10:30,080 --> 00:10:31,910
It's not going to execute this method anymore.

166
00:10:32,140 --> 00:10:35,060
Until we actually click on that button once again.

167
00:10:35,230 --> 00:10:37,480
OK that's the meaning of this router.

168
00:10:37,600 --> 00:10:39,870
It's not going to execute this short notification method.

169
00:10:39,870 --> 00:10:46,810
Here if this expression hit evaluates to true if one of these expressions here evaluates to true it's

170
00:10:46,810 --> 00:10:50,580
going to return and it's going to it's not going to execute this uncle anymore.

171
00:10:50,650 --> 00:10:55,150
I need to actually click on that button again in order to execute this method again.

172
00:10:55,240 --> 00:10:56,010
OK.

173
00:10:56,230 --> 00:10:58,370
So I put this written statement here.

174
00:10:58,540 --> 00:11:03,040
And if if this expression evaluates to true he's going to return and it's not going I should execute

175
00:11:03,040 --> 00:11:04,270
this line I've got here.

176
00:11:04,570 --> 00:11:06,910
So let's run our project again and see what happens.

177
00:11:06,920 --> 00:11:10,030
So now as you can see our application is running on the simulator.

178
00:11:10,030 --> 00:11:15,340
So if I actually click on this button here again and now as you can see it's not going to actually create

179
00:11:15,430 --> 00:11:20,030
notification for me because I didn't assign a value to this text.

180
00:11:20,070 --> 00:11:21,890
Eddie texts as you can see here.

181
00:11:21,940 --> 00:11:30,370
So if I actually assign a value for the title and if I don't assign a value for the text of this notification

182
00:11:30,760 --> 00:11:35,830
and if I click on this notify me again here it's not going to create a notification for me because I

183
00:11:35,830 --> 00:11:37,690
use this or operator here.

184
00:11:37,890 --> 00:11:38,170
OK.

185
00:11:38,200 --> 00:11:44,830
I said that if this expression even evaluates to true or if this expression evaluates to true then it's

186
00:11:44,830 --> 00:11:47,930
going to execute this return statement and it's not going to execute.

187
00:11:47,960 --> 00:11:48,900
And I've got here.

188
00:11:49,090 --> 00:11:49,660
OK.

189
00:11:49,870 --> 00:11:56,140
So I need to actually assign a value for the content text and if I notify me and if I actually click

190
00:11:56,140 --> 00:11:59,020
on this notify me button here again.

191
00:11:59,080 --> 00:12:03,030
And as you can see here it actually created this notification for me.

192
00:12:03,070 --> 00:12:03,760
OK.

193
00:12:03,850 --> 00:12:05,100
And if I click on it again.

194
00:12:05,140 --> 00:12:08,840
Now we will be guided to this main activity class here again.

195
00:12:08,890 --> 00:12:14,320
So hopefully that makes sense and I think that's enough for this tutorial.

196
00:12:14,560 --> 00:12:19,990
So here I just wanted to show you how you can actually create on notification later in discourse of

197
00:12:19,990 --> 00:12:25,900
we will be creating a more complex application and we will be using some of these features some of these

198
00:12:25,990 --> 00:12:28,470
notification features in our application.

199
00:12:28,600 --> 00:12:33,920
So for now I just I just want to show you the basics of creating a notification in Android application.

200
00:12:34,120 --> 00:12:36,370
So thank you very much for watching.

201
00:12:36,520 --> 00:12:41,740
And if you have any questions regarding notification in Android please post the discussion in the course

202
00:12:41,770 --> 00:12:44,800
and then I'll do my best to answer all of your questions.

203
00:12:44,800 --> 00:12:48,030
Thank you very much for watching and I'll see you in the next year or two earlier.

