1
00:00:00,960 --> 00:00:07,580
And here as you can see it says azing tasks should be ideally be used for short operations.

2
00:00:07,610 --> 00:00:10,640
OK so a few seconds at the most.

3
00:00:10,800 --> 00:00:11,280
OK.

4
00:00:11,280 --> 00:00:15,630
So this is going to be actually this glass is used for short operations.

5
00:00:15,780 --> 00:00:18,640
And as you can see here it's just a few seconds at the most.

6
00:00:18,660 --> 00:00:24,720
So if you have for example tasks such as downloading an image from the internet or such tasks in your

7
00:00:24,720 --> 00:00:27,730
application you can use this class azing task.

8
00:00:28,050 --> 00:00:34,860
But if you need to keep Fretz running for long periods of time for example you have a very heavy task

9
00:00:35,310 --> 00:00:36,010
and you can.

10
00:00:36,090 --> 00:00:37,950
And you need to actually.

11
00:00:38,430 --> 00:00:41,270
And it may take actually a lot of time.

12
00:00:41,430 --> 00:00:41,970
OK.

13
00:00:42,090 --> 00:00:48,630
It is highly recommended you use the various API is provided by the job that uty that can cart that

14
00:00:48,710 --> 00:00:51,380
concurrent package such as executor.

15
00:00:51,510 --> 00:00:57,930
Can are concurrent package such as the executer Fred Poole executed and future task.

16
00:00:57,960 --> 00:01:02,550
So these are classes actually inside this Java that you that can current package.

17
00:01:02,550 --> 00:01:08,310
I'll talk more about these classes later but for now we want to actually use this asynchronous async

18
00:01:08,310 --> 00:01:15,970
task class and it's just that an asynchronous task is defined by computation that runs on a background

19
00:01:15,990 --> 00:01:20,040
front and whose result is published under you like.

20
00:01:20,190 --> 00:01:22,340
OK so let me try to read this line again.

21
00:01:22,410 --> 00:01:30,630
An asynchronous task is defined by your computer nation that runs on a background Fred and whose result

22
00:01:30,870 --> 00:01:39,180
is published on the UI for it an asynchronous task is defined by free generic types called pro-ams progress

23
00:01:39,270 --> 00:01:40,150
resolved.

24
00:01:40,440 --> 00:01:46,250
OK so let's try to go back to what Android studio here as you can see inside these angle brackets.

25
00:01:46,260 --> 00:01:52,050
First of all I need to actually specify Dipodomys comma and the second level we need to specify the

26
00:01:52,050 --> 00:01:53,610
progress.

27
00:01:54,110 --> 00:01:58,950
OK comma and the first of all we need to specify the result.

28
00:01:59,100 --> 00:02:05,730
OK the result that I want to actually get from the Internet for example the Possum's is going to be

29
00:02:05,730 --> 00:02:06,670
the Padam meters.

30
00:02:06,680 --> 00:02:11,430
Ok the input that we actually put inside is async task is in the background.

31
00:02:11,540 --> 00:02:12,130
OK.

32
00:02:12,150 --> 00:02:14,050
So our input is going to be for example.

33
00:02:14,070 --> 00:02:15,020
And you are well.

34
00:02:15,120 --> 00:02:19,470
So as you can see here I have this you are well and I want to actually download this image from the

35
00:02:19,470 --> 00:02:22,770
internet and I actually chose this image here.

36
00:02:23,130 --> 00:02:28,470
So as you can see here I actually selected this of you image here and as you can see this is going to

37
00:02:28,470 --> 00:02:29,140
be the image.

38
00:02:29,160 --> 00:02:30,560
And here is do all.

39
00:02:30,630 --> 00:02:34,140
So the water is going to be off type strange putty.

40
00:02:34,200 --> 00:02:38,180
So the perimeter as you can see here is going to be type strange.

41
00:02:38,190 --> 00:02:44,550
So here I can just type in strange OK the data type is going to be of type string the data type of the

42
00:02:44,580 --> 00:02:49,920
input that you want to actually put inside the async task is going to be of types to change.

43
00:02:50,040 --> 00:02:55,070
And this is going to be that you are this you are is going to be inside to double quotes.

44
00:02:55,120 --> 00:03:02,510
So this is going to be of type strange that you want to actually put as a pedometer for this async task.

45
00:03:02,760 --> 00:03:06,540
So the second parimutuel as you can see here is progress.

46
00:03:06,540 --> 00:03:12,660
So this progress paramita it is going to show us how much of the contents have been actually downloaded

47
00:03:12,660 --> 00:03:13,570
from the Internet.

48
00:03:13,650 --> 00:03:20,740
We can actually see what what percentage of the contents have been downloaded from the Internet and

49
00:03:20,740 --> 00:03:27,150
then actually put that value somewhere in order to show to the user that what is going to be.

50
00:03:27,180 --> 00:03:33,180
How much time is going to take for example to download this image this particular image from the Internet.

51
00:03:33,210 --> 00:03:35,320
So that's the job of this pedometer.

52
00:03:35,550 --> 00:03:42,970
And in the Android documentation as you can see here we have these descriptions here async tasks are

53
00:03:42,990 --> 00:03:43,920
generic types.

54
00:03:43,920 --> 00:03:51,510
And as you can see and it says patta progress the type of the Procrustes units published the type of

55
00:03:51,510 --> 00:03:56,480
the Procrustes is published during the background computation.

56
00:03:56,490 --> 00:03:57,460
OK.

57
00:03:57,960 --> 00:04:04,670
So and as you can see here we have this result that type of the result of the background can computation.

58
00:04:04,890 --> 00:04:09,560
So as you can see here because we want to actually download this image from the Internet.

59
00:04:09,630 --> 00:04:12,000
So if you want to actually get an image from the Internet.

60
00:04:12,000 --> 00:04:13,180
Right.

61
00:04:13,320 --> 00:04:16,240
So that image is going to be offtake bitmap.

62
00:04:16,340 --> 00:04:23,040
OK this is going to be the output the outputs that I want to get from these async task class is going

63
00:04:23,040 --> 00:04:27,140
to be of type bitmap so that progress is going to be what.

64
00:04:27,180 --> 00:04:29,810
I don't want to actually get disvalue.

65
00:04:29,970 --> 00:04:30,300
OK.

66
00:04:30,320 --> 00:04:36,450
Get these units published of the day for example and the image is downloaded from the internet.

67
00:04:36,480 --> 00:04:39,370
I just want to put this Voyt value here.

68
00:04:39,540 --> 00:04:47,250
I don't want to get any value here as a progress and the result is going to be offtake bitmap the bitmap

69
00:04:47,250 --> 00:04:48,980
is actually the output.

70
00:04:49,140 --> 00:04:55,110
So this thrain is the input that I want to put inside these async task and repeat map is the output

71
00:04:55,120 --> 00:04:56,200
right.

72
00:04:56,280 --> 00:05:02,750
So now I need to actually open and close this class using these curly braces but this opening curly

73
00:05:02,750 --> 00:05:05,660
brace and these are closing calibrates.

74
00:05:05,660 --> 00:05:08,780
So now we need to actually implement free methods here.

75
00:05:08,810 --> 00:05:13,490
The first one is Vendi when the image is actually is going to download from the Internet.

76
00:05:13,490 --> 00:05:14,560
OK.

77
00:05:15,080 --> 00:05:21,890
Actually before downloading an image from the Internet is going to be dismembered on poorly executed

78
00:05:21,890 --> 00:05:22,700
Meffert.

79
00:05:22,850 --> 00:05:27,040
So this is going to be executed before downloading an image from the Internet.

80
00:05:27,140 --> 00:05:27,810
OK.

81
00:05:28,200 --> 00:05:32,930
The second effect is actually when the image is being downloaded from the Internet.

82
00:05:32,960 --> 00:05:35,980
So that task is going to be in the background right.

83
00:05:35,990 --> 00:05:41,690
So the name of this Meffert is going to be do in background as you can see here and here as you can

84
00:05:41,690 --> 00:05:50,300
see the return type as of this Mufti's bitmap because here as you can see I specified that the output

85
00:05:50,300 --> 00:05:52,520
type is going to be of type bitmap.

86
00:05:52,790 --> 00:05:54,380
So I just select this Meffert here.

87
00:05:54,560 --> 00:05:58,030
And as you can see here this is that Meffert to in background.

88
00:05:58,400 --> 00:06:03,620
And the first method is going to be vente the image is actually downloaded from the Internet.

89
00:06:03,680 --> 00:06:08,870
And the task of downloading is finished and then I want to put that image on the image for you and the

90
00:06:08,870 --> 00:06:11,000
user interface as you can see here.

91
00:06:11,150 --> 00:06:14,870
So that if it is going to be on post executes.

92
00:06:15,290 --> 00:06:20,200
So these are the free important methods of this async task class.

93
00:06:20,210 --> 00:06:20,910
OK.

94
00:06:21,320 --> 00:06:27,170
So now inside this download image task class as you can see this is actually an inner class that is

95
00:06:27,170 --> 00:06:29,310
inside of this main activity class.

96
00:06:29,390 --> 00:06:35,120
So you can access these at user interface components variables or these methods that are inside the

97
00:06:35,120 --> 00:06:35,810
outer class.

98
00:06:35,810 --> 00:06:36,270
OK.

99
00:06:36,470 --> 00:06:42,440
So inside this download image task class I want to actually first of all declare two objects the first

100
00:06:42,440 --> 00:06:45,380
one is actually of type progress they like.

101
00:06:45,500 --> 00:06:51,770
OK so you want to actually show it to the user a dialogue in order to let them know that the application

102
00:06:51,770 --> 00:06:54,220
is actually downloading an image from the Internet.

103
00:06:54,620 --> 00:06:57,990
And the name of this object is progress like semicolon.

104
00:06:58,150 --> 00:06:58,780
OK.

105
00:06:59,090 --> 00:07:04,350
And the second object that I want to actually declare here is of type context.

106
00:07:05,060 --> 00:07:07,540
And the name of this context is context.

107
00:07:07,640 --> 00:07:13,790
And then I need to put a semicolon at the end of my statement and then here I need to actually specify

108
00:07:13,790 --> 00:07:17,380
a constructor for this download image task class.

109
00:07:17,390 --> 00:07:24,740
So here I can just type in public and the name of the constructor must be the same as the name as the

110
00:07:24,740 --> 00:07:27,080
name of this download image task class.

111
00:07:27,200 --> 00:07:31,390
So here I can just type in download image task OK.

112
00:07:31,460 --> 00:07:36,590
And then I need to put a pair of practices here and then I need to open and close this constructed by

113
00:07:36,590 --> 00:07:38,410
using these curly braces.

114
00:07:38,480 --> 00:07:45,790
And here I want to specify that these are constructed actually accepts an argument of type context.

115
00:07:45,980 --> 00:07:49,160
OK so the name of this argument is going to be context.

116
00:07:49,160 --> 00:07:49,760
OK.

117
00:07:50,070 --> 00:07:56,630
And inside these are constructor you want to initialize these two objects that are actually declared

118
00:07:56,690 --> 00:07:59,070
inside the standard image task class.

119
00:07:59,090 --> 00:08:04,550
So the first one is progress Stalock assignment operator.

120
00:08:04,550 --> 00:08:10,830
And here I can just typing new progress dialog.

121
00:08:11,000 --> 00:08:17,360
And for the context as you can see here I can pass this context here and then put a semicolon at the

122
00:08:17,360 --> 00:08:19,290
end of my statement.

123
00:08:19,310 --> 00:08:25,040
And here are before initializing this progress Stalock I need to actually initialize this context object

124
00:08:25,490 --> 00:08:29,840
because I am actually passing this context as a path emitter to this.

125
00:08:29,840 --> 00:08:32,320
A constructed of this progress Daler class.

126
00:08:32,330 --> 00:08:36,510
So here again I'll refer to the name of this context assignment operator.

127
00:08:36,680 --> 00:08:42,400
So here as you can see I made this mistake when I actually referred to the name of this context here

128
00:08:42,400 --> 00:08:47,870
it is that it is actually fairly in to this context as a Padam here because as you can see the name

129
00:08:47,870 --> 00:08:54,610
of this instance variable here as you can see is actually the same as the name of this argument.

130
00:08:54,620 --> 00:08:59,840
So when I actually inside this when I'm in say this a constructor and of a and I refer to the name of

131
00:08:59,840 --> 00:09:02,330
this context it's going to actually refer to the.

132
00:09:02,340 --> 00:09:04,730
To this construct to this context as a pattern.

133
00:09:04,730 --> 00:09:05,350
OK.

134
00:09:05,630 --> 00:09:09,670
So here I need to put this these here these that context.

135
00:09:09,680 --> 00:09:16,410
So it is now referring to this context here inside this class download image task assignment operator.

136
00:09:16,430 --> 00:09:20,020
So now you want to refer to the name of this context here as a padded me.

137
00:09:20,060 --> 00:09:20,600
OK.

138
00:09:20,900 --> 00:09:27,710
So now I am actually initializing this context that I actually get from this pattern meter is argument

139
00:09:28,100 --> 00:09:34,250
here I am initializing the context here as you can see here this context context as you can see here

140
00:09:34,280 --> 00:09:40,130
I am assigning this context that I get as a perimeter to this context here as you can see inside this

141
00:09:40,130 --> 00:09:41,550
download image task.

142
00:09:41,990 --> 00:09:49,340
So now that I can initialised my two objects now inside this on pre-text acute MFA Meffert when actually

143
00:09:49,340 --> 00:09:50,940
put in some lines of code here.

144
00:09:50,960 --> 00:09:57,440
So when the user actually wants to download the image from the internet why by clicking on the spot

145
00:09:57,440 --> 00:10:03,930
in here I want to show them a message dialogue in order to let them know that an image is being downloaded

146
00:10:03,960 --> 00:10:05,900
from the internet so they should wait.

147
00:10:05,970 --> 00:10:06,580
OK.

148
00:10:06,840 --> 00:10:12,690
So in order to do that as you can see I have this progress dialog uptick here so I can just refer to

149
00:10:12,690 --> 00:10:19,770
the name of this object Proclus dialogue that sit message as you can see I mean it is an acute Meffert.

150
00:10:19,770 --> 00:10:20,240
OK.

151
00:10:20,320 --> 00:10:26,750
So this is going to be executed just before I actually click on the button download button and then

152
00:10:26,810 --> 00:10:29,500
it can actually download the image from the Internet.

153
00:10:29,610 --> 00:10:32,130
So this is the NPE execute method right.

154
00:10:32,250 --> 00:10:35,320
Set message and inserted prentices.

155
00:10:35,400 --> 00:10:38,700
I put the two double quotes on here I can just put the message.

156
00:10:38,790 --> 00:10:45,490
For example downloading image.

157
00:10:45,680 --> 00:10:46,320
Please visit

158
00:10:49,640 --> 00:10:49,960
OK.

