Hello this is Martez accorded.
And in this story or let's actually continue building our floating new application.
So inside our main activity class let's declare a button.
So first let me tell you that you should always declare your instance variables as private.
So first we put the private keyboard and then your way to create a variable of type.
But in the name of our variable is going to be PTEN floating semicolon.
So here we just declared around the table.
Now it's time to initialize around the table inside our uncreate me if it's a little bit here and floating.
Assignment operator let's cast it to a button object find view by ID or that ID that PTEN floating semicolon.
So now I'm going to actually create a listener an uncle listener for this button so that whenever a
user interacts with this button you're going to be notified.
So let's say between BT or floating that set unclick listener near you.
So now in order to use the autocomplete feature of Android stood you just hold down the shift key on
my keyboard and press landlady Revici on your keyboard.
So now it's going I should show you this option if you click unclick listener two curly braces and inside
the reproducers you can see these three dots.
Choose this one and then press on until you on your keyboard.
So now the Android suit is going to put all of these codes for you it can actually create an anonymous
in a class for you.
And inside is in an anonymous senior class we have this unclick the uncle's method.
So is this method you're going to say we have a method called Start service because we need a service.
And so the practice is to say new.
So first I can tell you that it's going to be the prime method of this start service Smurfette.
So again I'm going to choose the autocomplete feature of Android studio so you can see that this Myford
start service needs an argument of type intent here.
So here we just see new because you want to create a new uptick a new object of intent intent with capital
i.e. inside the practices we're going to pass two arguments the first one is going to be the context.
The context is the main activity.
So if we say main activity that this come up.
And the second argument is going to be the class that is going to actually be the service.
So the second class is going to play the role of a service.
So if you're going to actually name it as a float service floating you say let's name it.
Floating view because it's more meaningful fluting View service.
So now let's put a semicolon at the end of our method here.
Now it's actually showing us an error.
If I actually hover over this floating view service here it says cannot resolve symbol Flaten view service
and that's because we haven't still created this class.
We need to create a new class.
Right.
So for it make sure that you put that class here because it's a class.
So when you put that class here is going to actually put this package context for you to keyboard.
So it's a new feature in androids to do in order to specify the role of each argument.
Don't worry about this one.
It's a new feature.
It's just the new feature is it's not going to actually affect how Android studio works.
So now it's just a floating View service.
I'm going to solve this problem.
A new solution is to actually as you can see I'm highlighting this line of code here right.
And if I actually click on this fluty view service is going to show us a little red ball up here at
the left hand side right now if I click on this one it says create class floating view service.
So by just clicking on this option it's going to create the class for us automatically we don't have
to.
For example click on find new class.
I just need to open the I you first so in order to create a class you need to open the Android view.
And then here open the package of in the Java folder and then click on the package and then right click
on this package.
New.
For example Java class right you would have to do that.
I just need to just click on this or this floating view service that last year and then it's going to
show us this little red ball.
I just need to click on it and it's going to show us this often create class floating users.
Just click on it and then it's going to actually open this little window here.
So it's his destination package.
So this is going to be the destination package.
So this is the same package that we have the main activity.
And then we have the target this destination that directory.
Don't change these settings here.
Leave them as default and just click on.
And now a new class is actually created inside our project.
If I show you the Android view here you can see that inside of a there.
And we have this package here right inside this package.
Now this class has created a floating view service.
So not only that we can't establish order to make this wider.
So we had a class called Floating view set.
So because this is actually a service it has to be Puplick.
So before the class keyboard to put the public key vote here because we are going to use this service
inside our project we must declare this class as public.
So let's go inside the curly braces of this class and first of all let me tell you that because this
class is going to play the role of a service this class must extend from the service class.
So that is going to be.
And these are relationships between floating View service class and the actual service class inside
the Android library.
So here we are going to say a public class floating view service expense service.
Right.
So we are using a service class inside the Android app packet as you can see this line of code.
It has import Android app package.
So this is the curly braces of this floating view service.
Now we have to override a method that is called on buying.
So now that the override that is if it is on bind my error is gone.
Vlei we had to override the Smurfette.
So in order to find out why we have to override to dismiss it you can actually take a look at the documentation
of the service class or if you are using a Mac you just need to hold down the comments on your keyboard
and then click on the service or if you are using Windows machine you just need to hold down the control
key on your keyboard and then click on servies.
Now it's actually guided us to the documentation of the service class as you can see it is actually
an abstract class and the merits of the abstract class here.
So let's actually find the bind method.
So let's actually scroll down here in order to find the on method.
So in order to find the method we can actually search for the name of them if it here I can hold down
the comment on my keyboard and then present the letter on my keyboard and I can just search for the
and bind method.
And if you're using a Windows machine you just need to hold down the control key on your keyboard and
then present the letter if key on your keyboard.
In order to search for a specific valuable or name or the name of the method as you can see we found
that method here Puplick abstract the binder on bind as you can see there is no implementation for this
method here.
This means that any class that extends from the service class must provide an implementation for this
abstract CP M effort.
So let's close this service that of our class here.
Now you know we had to override this method and provide an implementation for this.
As you can see by default it just returns not.
So now let's see what does this unbind method do.
So in order to see the documentation of these on bind method you just need to hold down the command
key on your keyboard and then click on this service here.
If you are using a Windows machine you just need to hold down the control key on your keyboard and then
click on the service here.
And now let's search for the on unbind method on line.
So you know that search for a specific method or a variable.
You just need to hold down the common key on your keyboard and then present that key on your keyboard.
And if you are using a Windows machine you need to hold down the control key on your keyboard and then
press undeleted key on your keyboard in order to search for a specific keyboard.
So now here it is the on buying method.
So let's see at the top at the above of the Smurfette unbind we have this documentation of this unbind
method.
So let's read this documentation it says Return it means dismiss it returns.
Actually the communication channel to the service may return gnarl or nothing.
If clients cannot bind to the service so if it just returns the communication channel to the service
and it's going to actually determine whether the clients actually access the service or not binded a
service or not.
So now let's close this so we start off by and let's go back to our Latino Buel said we start over.
So here it is our class.
Now we need to declare this class inside the Android manifest fight.
So that's open the Android view and in here inside this app folder we have this manifest folder by just
double clicking and this folder the manifest that XML file is actually opened.
Let me double click on this to happen to make this area wider.
Now inside this is enemy application tag we need to declare the service.
So here it is the ending tag of this application.
Right.
So just let's create some space here before the ending tag.
Now let's open attack and let's say that we have a service and our service is dead.
Floating eusbio as you can see the auto feature the autocomplete feature of Android suit you automatically
identifies the service inside our project because they're floating View service class extends from the
service class.
So it is a service.
So now we can select this option and then we can still close this service like by just putting a slash
up and then a closing time.
Now this is our service and we need to also put a permission here insights manifest here at the top
before this application I need to use the permission and the name of this permission is system alert
window.
So it's open attack let's say uses permission and just step in here and with the permission dot system
alert.
If we're just taking a system underlined alert.
So here it is the actually option and we can select it and then press and keyboard.
And just by putting a slash here we can self close the stack.
So we use the pool this permission here system alerts when do we need to use this permission.
If you actually want to use the service here inside your project.
So that's it.
Let's close this android manifested exemplified.
And now I think that's enough for this tutorial in the next story.
We're going to actually continue adding features to our application.
So thanks very much for watching.
If you have any questions about these concepts that I have taught you so far please post this in the
course and then I will do my best to answer all of your questions.
And I look forward to seeing you in the next tutorial.