1
00:00:00,240 --> 00:00:02,170
Hello this is Martez accorded.

2
00:00:02,370 --> 00:00:08,080
And in this story or let's actually continue building our floating new application.

3
00:00:08,100 --> 00:00:12,030
So inside our main activity class let's declare a button.

4
00:00:12,060 --> 00:00:17,780
So first let me tell you that you should always declare your instance variables as private.

5
00:00:17,790 --> 00:00:23,320
So first we put the private keyboard and then your way to create a variable of type.

6
00:00:23,400 --> 00:00:29,620
But in the name of our variable is going to be PTEN floating semicolon.

7
00:00:30,060 --> 00:00:32,300
So here we just declared around the table.

8
00:00:32,340 --> 00:00:38,020
Now it's time to initialize around the table inside our uncreate me if it's a little bit here and floating.

9
00:00:38,190 --> 00:00:47,200
Assignment operator let's cast it to a button object find view by ID or that ID that PTEN floating semicolon.

10
00:00:47,520 --> 00:00:53,970
So now I'm going to actually create a listener an uncle listener for this button so that whenever a

11
00:00:53,970 --> 00:00:57,660
user interacts with this button you're going to be notified.

12
00:00:57,660 --> 00:01:03,130
So let's say between BT or floating that set unclick listener near you.

13
00:01:03,300 --> 00:01:10,980
So now in order to use the autocomplete feature of Android stood you just hold down the shift key on

14
00:01:10,980 --> 00:01:14,680
my keyboard and press landlady Revici on your keyboard.

15
00:01:14,850 --> 00:01:20,040
So now it's going I should show you this option if you click unclick listener two curly braces and inside

16
00:01:20,040 --> 00:01:23,000
the reproducers you can see these three dots.

17
00:01:23,040 --> 00:01:25,710
Choose this one and then press on until you on your keyboard.

18
00:01:25,710 --> 00:01:31,170
So now the Android suit is going to put all of these codes for you it can actually create an anonymous

19
00:01:31,170 --> 00:01:32,090
in a class for you.

20
00:01:32,100 --> 00:01:37,210
And inside is in an anonymous senior class we have this unclick the uncle's method.

21
00:01:37,310 --> 00:01:45,530
So is this method you're going to say we have a method called Start service because we need a service.

22
00:01:45,850 --> 00:01:49,400
And so the practice is to say new.

23
00:01:49,770 --> 00:01:53,850
So first I can tell you that it's going to be the prime method of this start service Smurfette.

24
00:01:53,850 --> 00:01:59,640
So again I'm going to choose the autocomplete feature of Android studio so you can see that this Myford

25
00:01:59,640 --> 00:02:04,200
start service needs an argument of type intent here.

26
00:02:04,260 --> 00:02:13,050
So here we just see new because you want to create a new uptick a new object of intent intent with capital

27
00:02:13,120 --> 00:02:19,600
i.e. inside the practices we're going to pass two arguments the first one is going to be the context.

28
00:02:19,680 --> 00:02:21,560
The context is the main activity.

29
00:02:21,690 --> 00:02:25,470
So if we say main activity that this come up.

30
00:02:25,770 --> 00:02:33,000
And the second argument is going to be the class that is going to actually be the service.

31
00:02:33,330 --> 00:02:37,910
So the second class is going to play the role of a service.

32
00:02:37,920 --> 00:02:43,730
So if you're going to actually name it as a float service floating you say let's name it.

33
00:02:43,730 --> 00:02:48,760
Floating view because it's more meaningful fluting View service.

34
00:02:48,930 --> 00:02:54,540
So now let's put a semicolon at the end of our method here.

35
00:02:54,570 --> 00:02:56,240
Now it's actually showing us an error.

36
00:02:56,250 --> 00:03:02,600
If I actually hover over this floating view service here it says cannot resolve symbol Flaten view service

37
00:03:02,640 --> 00:03:06,630
and that's because we haven't still created this class.

38
00:03:06,660 --> 00:03:08,180
We need to create a new class.

39
00:03:08,220 --> 00:03:09,080
Right.

40
00:03:09,090 --> 00:03:15,320
So for it make sure that you put that class here because it's a class.

41
00:03:15,450 --> 00:03:20,030
So when you put that class here is going to actually put this package context for you to keyboard.

42
00:03:20,070 --> 00:03:26,130
So it's a new feature in androids to do in order to specify the role of each argument.

43
00:03:26,130 --> 00:03:27,240
Don't worry about this one.

44
00:03:27,240 --> 00:03:28,400
It's a new feature.

45
00:03:28,450 --> 00:03:33,190
It's just the new feature is it's not going to actually affect how Android studio works.

46
00:03:33,210 --> 00:03:36,460
So now it's just a floating View service.

47
00:03:36,830 --> 00:03:38,660
I'm going to solve this problem.

48
00:03:39,120 --> 00:03:45,310
A new solution is to actually as you can see I'm highlighting this line of code here right.

49
00:03:45,540 --> 00:03:53,070
And if I actually click on this fluty view service is going to show us a little red ball up here at

50
00:03:53,070 --> 00:03:59,540
the left hand side right now if I click on this one it says create class floating view service.

51
00:03:59,670 --> 00:04:04,710
So by just clicking on this option it's going to create the class for us automatically we don't have

52
00:04:04,710 --> 00:04:05,470
to.

53
00:04:05,820 --> 00:04:09,820
For example click on find new class.

54
00:04:09,840 --> 00:04:15,500
I just need to open the I you first so in order to create a class you need to open the Android view.

55
00:04:15,570 --> 00:04:20,070
And then here open the package of in the Java folder and then click on the package and then right click

56
00:04:20,070 --> 00:04:21,310
on this package.

57
00:04:21,360 --> 00:04:21,860
New.

58
00:04:21,870 --> 00:04:25,510
For example Java class right you would have to do that.

59
00:04:25,590 --> 00:04:32,310
I just need to just click on this or this floating view service that last year and then it's going to

60
00:04:32,310 --> 00:04:34,970
show us this little red ball.

61
00:04:35,010 --> 00:04:38,940
I just need to click on it and it's going to show us this often create class floating users.

62
00:04:38,970 --> 00:04:44,090
Just click on it and then it's going to actually open this little window here.

63
00:04:44,160 --> 00:04:45,650
So it's his destination package.

64
00:04:45,660 --> 00:04:47,820
So this is going to be the destination package.

65
00:04:47,820 --> 00:04:51,390
So this is the same package that we have the main activity.

66
00:04:51,750 --> 00:04:54,620
And then we have the target this destination that directory.

67
00:04:54,720 --> 00:04:57,700
Don't change these settings here.

68
00:04:57,810 --> 00:05:00,350
Leave them as default and just click on.

69
00:05:00,810 --> 00:05:05,330
And now a new class is actually created inside our project.

70
00:05:05,340 --> 00:05:09,330
If I show you the Android view here you can see that inside of a there.

71
00:05:09,540 --> 00:05:12,450
And we have this package here right inside this package.

72
00:05:12,450 --> 00:05:15,230
Now this class has created a floating view service.

73
00:05:15,480 --> 00:05:18,250
So not only that we can't establish order to make this wider.

74
00:05:18,270 --> 00:05:20,580
So we had a class called Floating view set.

75
00:05:20,620 --> 00:05:24,960
So because this is actually a service it has to be Puplick.

76
00:05:24,990 --> 00:05:31,920
So before the class keyboard to put the public key vote here because we are going to use this service

77
00:05:31,920 --> 00:05:36,110
inside our project we must declare this class as public.

78
00:05:36,120 --> 00:05:42,030
So let's go inside the curly braces of this class and first of all let me tell you that because this

79
00:05:42,030 --> 00:05:48,880
class is going to play the role of a service this class must extend from the service class.

80
00:05:49,050 --> 00:05:50,430
So that is going to be.

81
00:05:50,610 --> 00:05:56,490
And these are relationships between floating View service class and the actual service class inside

82
00:05:56,500 --> 00:05:57,880
the Android library.

83
00:05:58,080 --> 00:06:05,460
So here we are going to say a public class floating view service expense service.

84
00:06:05,550 --> 00:06:05,960
Right.

85
00:06:06,120 --> 00:06:12,680
So we are using a service class inside the Android app packet as you can see this line of code.

86
00:06:12,680 --> 00:06:15,340
It has import Android app package.

87
00:06:15,570 --> 00:06:19,680
So this is the curly braces of this floating view service.

88
00:06:19,740 --> 00:06:24,860
Now we have to override a method that is called on buying.

89
00:06:24,870 --> 00:06:28,830
So now that the override that is if it is on bind my error is gone.

90
00:06:28,830 --> 00:06:31,130
Vlei we had to override the Smurfette.

91
00:06:31,170 --> 00:06:37,320
So in order to find out why we have to override to dismiss it you can actually take a look at the documentation

92
00:06:37,350 --> 00:06:42,960
of the service class or if you are using a Mac you just need to hold down the comments on your keyboard

93
00:06:43,350 --> 00:06:48,060
and then click on the service or if you are using Windows machine you just need to hold down the control

94
00:06:48,090 --> 00:06:50,700
key on your keyboard and then click on servies.

95
00:06:50,730 --> 00:06:56,460
Now it's actually guided us to the documentation of the service class as you can see it is actually

96
00:06:56,460 --> 00:07:00,920
an abstract class and the merits of the abstract class here.

97
00:07:01,020 --> 00:07:04,260
So let's actually find the bind method.

98
00:07:04,650 --> 00:07:09,180
So let's actually scroll down here in order to find the on method.

99
00:07:09,180 --> 00:07:14,760
So in order to find the method we can actually search for the name of them if it here I can hold down

100
00:07:14,760 --> 00:07:21,000
the comment on my keyboard and then present the letter on my keyboard and I can just search for the

101
00:07:21,080 --> 00:07:22,660
and bind method.

102
00:07:22,680 --> 00:07:28,260
And if you're using a Windows machine you just need to hold down the control key on your keyboard and

103
00:07:28,260 --> 00:07:30,310
then present the letter if key on your keyboard.

104
00:07:30,330 --> 00:07:36,360
In order to search for a specific valuable or name or the name of the method as you can see we found

105
00:07:36,360 --> 00:07:42,810
that method here Puplick abstract the binder on bind as you can see there is no implementation for this

106
00:07:42,810 --> 00:07:43,910
method here.

107
00:07:43,920 --> 00:07:52,110
This means that any class that extends from the service class must provide an implementation for this

108
00:07:52,110 --> 00:07:53,820
abstract CP M effort.

109
00:07:54,060 --> 00:07:58,190
So let's close this service that of our class here.

110
00:07:58,500 --> 00:08:03,230
Now you know we had to override this method and provide an implementation for this.

111
00:08:03,270 --> 00:08:06,220
As you can see by default it just returns not.

112
00:08:06,270 --> 00:08:10,530
So now let's see what does this unbind method do.

113
00:08:10,860 --> 00:08:16,410
So in order to see the documentation of these on bind method you just need to hold down the command

114
00:08:16,410 --> 00:08:19,270
key on your keyboard and then click on this service here.

115
00:08:19,290 --> 00:08:23,790
If you are using a Windows machine you just need to hold down the control key on your keyboard and then

116
00:08:23,790 --> 00:08:25,630
click on the service here.

117
00:08:26,120 --> 00:08:30,870
And now let's search for the on unbind method on line.

118
00:08:30,930 --> 00:08:34,180
So you know that search for a specific method or a variable.

119
00:08:34,290 --> 00:08:40,420
You just need to hold down the common key on your keyboard and then present that key on your keyboard.

120
00:08:40,470 --> 00:08:45,360
And if you are using a Windows machine you need to hold down the control key on your keyboard and then

121
00:08:45,360 --> 00:08:50,390
press undeleted key on your keyboard in order to search for a specific keyboard.

122
00:08:50,640 --> 00:08:52,710
So now here it is the on buying method.

123
00:08:52,920 --> 00:09:03,030
So let's see at the top at the above of the Smurfette unbind we have this documentation of this unbind

124
00:09:03,120 --> 00:09:03,540
method.

125
00:09:03,570 --> 00:09:09,000
So let's read this documentation it says Return it means dismiss it returns.

126
00:09:09,000 --> 00:09:16,650
Actually the communication channel to the service may return gnarl or nothing.

127
00:09:16,890 --> 00:09:25,340
If clients cannot bind to the service so if it just returns the communication channel to the service

128
00:09:25,970 --> 00:09:31,790
and it's going to actually determine whether the clients actually access the service or not binded a

129
00:09:31,790 --> 00:09:32,990
service or not.

130
00:09:32,990 --> 00:09:38,440
So now let's close this so we start off by and let's go back to our Latino Buel said we start over.

131
00:09:38,450 --> 00:09:40,070
So here it is our class.

132
00:09:40,070 --> 00:09:45,970
Now we need to declare this class inside the Android manifest fight.

133
00:09:46,100 --> 00:09:53,710
So that's open the Android view and in here inside this app folder we have this manifest folder by just

134
00:09:53,780 --> 00:09:58,840
double clicking and this folder the manifest that XML file is actually opened.

135
00:09:59,000 --> 00:10:01,980
Let me double click on this to happen to make this area wider.

136
00:10:02,420 --> 00:10:08,280
Now inside this is enemy application tag we need to declare the service.

137
00:10:08,540 --> 00:10:11,390
So here it is the ending tag of this application.

138
00:10:11,410 --> 00:10:11,800
Right.

139
00:10:11,960 --> 00:10:16,420
So just let's create some space here before the ending tag.

140
00:10:16,460 --> 00:10:23,840
Now let's open attack and let's say that we have a service and our service is dead.

141
00:10:23,920 --> 00:10:30,140
Floating eusbio as you can see the auto feature the autocomplete feature of Android suit you automatically

142
00:10:30,440 --> 00:10:37,760
identifies the service inside our project because they're floating View service class extends from the

143
00:10:37,760 --> 00:10:38,440
service class.

144
00:10:38,450 --> 00:10:39,820
So it is a service.

145
00:10:40,100 --> 00:10:46,980
So now we can select this option and then we can still close this service like by just putting a slash

146
00:10:47,390 --> 00:10:49,730
up and then a closing time.

147
00:10:50,000 --> 00:10:58,690
Now this is our service and we need to also put a permission here insights manifest here at the top

148
00:10:59,110 --> 00:11:05,860
before this application I need to use the permission and the name of this permission is system alert

149
00:11:05,920 --> 00:11:06,470
window.

150
00:11:06,550 --> 00:11:15,460
So it's open attack let's say uses permission and just step in here and with the permission dot system

151
00:11:15,870 --> 00:11:16,640
alert.

152
00:11:16,690 --> 00:11:21,590
If we're just taking a system underlined alert.

153
00:11:21,640 --> 00:11:27,150
So here it is the actually option and we can select it and then press and keyboard.

154
00:11:27,380 --> 00:11:32,830
And just by putting a slash here we can self close the stack.

155
00:11:32,920 --> 00:11:38,420
So we use the pool this permission here system alerts when do we need to use this permission.

156
00:11:38,440 --> 00:11:42,580
If you actually want to use the service here inside your project.

157
00:11:42,580 --> 00:11:43,210
So that's it.

158
00:11:43,210 --> 00:11:46,330
Let's close this android manifested exemplified.

159
00:11:46,570 --> 00:11:50,740
And now I think that's enough for this tutorial in the next story.

160
00:11:50,950 --> 00:11:55,120
We're going to actually continue adding features to our application.

161
00:11:55,270 --> 00:11:56,860
So thanks very much for watching.

162
00:11:56,860 --> 00:12:01,930
If you have any questions about these concepts that I have taught you so far please post this in the

163
00:12:01,930 --> 00:12:05,770
course and then I will do my best to answer all of your questions.

164
00:12:06,010 --> 00:12:09,340
And I look forward to seeing you in the next tutorial.

