So now let's actually declare some variables here inside the main activity class.
So now here I just started typing firebase database and the name of this variable is going to be database
assignment operator.
And here I want to actually create an instance from our database.
So here I can say Firebrace database start with instance and then I need to put a semicolon at the end
of my statement.
So in this way you are actually getting on an instance of our database so let's actually open our web
browser here and now actually go to our console on here.
As you can see we just need to select our project So our project is this one at 60 65 right.
So let's actually click on it.
And then here to just click on this database here.
And now click on these rules tab.
So now let's actually change the rules so that the users that are not authenticated can also interact
with the database.
So let's actually change the rules here so here.
Just delete this exclamation mark and put an equal operator.
And then here just delete this exclamation mark and put any quote operator here and then click publish.
So now it says rules published.
So let's actually click on the state I'd have here again.
And now here it is our database instance right.
So when we say that we have actually an instance from our database this is that instance right.
And now as you can see here I actually initialized this valuable right inside our class.
It's not a good program in practice to initialize your valuables inside your class.
It's always recommended that you just declared your valuables here inside just inside your main activity
class and then inside your uncreate Smurfette initialized them.
Why.
Because for example when you are actually transitioning to another activity and when you want to actually
come back to this activity again for example this class display an activity here may be actually garbage
collected and maybe just eliminated from our memory.
So in that case we may have no instance for a modified firebase database.
But if we have this uncreate method here inside our uncreative it just initialize my valuable here.
Every time that this main activity here is actually shown to the user this uncreate Smurfette is going
to be called as the first method that is actually being caught.
Right.
So let's actually delete this initialiser here and here.
Let's just put a semicolon here and now as you can see I just declare my variable my firebase database
here right.
I didn't initialize it yet.
So let's actually declare that let's actually declare another variable of type database reference.
So now you've got to have a reference to this instance.
Right.
It's not enough to just have the database instance.
We just need to have a reference to this database to this instance.
So let's go back to what androids would use or database offense and the name is database reference assignment
operator.
And here I just need to refer to the name of this database that gets a reference and then put a semicolon
at the end of your statement.
And again as you can see I just initialized it here right.
It's not a good Procrit programming practice to initialize your variables here especially your objects
as you can see here we have objects but it's good it's actually it's not a problem to initialize your
primitive data types such as ints or floats or char.
It's not a problem but for your objects.
Always make sure to initialize them inside your methods such as uncreate or on resume.
So you already are familiar with the android lifecycle methods.
So again let's actually delete this initialization here.
So here I wanted to actually talk about this initialising variables especially the objects inside your
class.
And what's the difference between initializing them inside your class and initializing them.
Inside the method such as this uncreate Smurfette.
Right.
So now let's go inside this uncreate Smurfette.
And here inside this uncreate Meffert let's just initialize our variables here.
For example this one firebase the top is.
So inside this uncreate I can say database assignment operator and then here I can just say firebase
database start get instance and then I need to put a semicolon he added of my statement.
And now let's initialize our database reference.
So here I tend to say database reference assignment operator.
And then here I can refer to the name of this database that gets through a fence and then I need to
put a semicolon at the end of my statement.
So we managed to actually declare and initialize all of a firebase database object and database reference
object.
Right.
So now let's actually put some more lines of code here.
Inside is uncreate method.
The first thing that we should do here is to actually make the spot in BT and send data to separate
the spot in actually a listener to the clicks of the user.
So let me show you the emulator as you can see this is our emulator.
And now I want to actually read these data.
For example the Buxar name the Buxar punch power and the box of punch speed.
And I want to actually get these values from these texts and I want to send them to the server whenever
the user clicks on the spot and send data.
So do that here inside this uncreate benefit I meant to say PTEN send data to server that said unclick
listener.
And here I just need to put the new key word here and then just hold the shift key on your keyboard
and then press on the leader the key on your keyboard.
And now the autocomplete feature of the Android studio is actually helping us to choose this option.
Unclick listener right.
So as this one here and in person enter key on your keyboard.
And now as you can see here are the Android studio automatically put these lines of code here for us.
So again let me tell you that we have actually an anonymous in a class and this anonymous in a class
is actually implemented in the they view that and click click center interface.
And because that anonymous class is implementing this interface unclick listener that class must actually
pro-white an implementation for this on a college Meffert.
So the remember that anonymous classes are classes without names.
Right.
So here we have actually a class but that class doesn't have a name.
So now here we are actually inside a class and now we are going to have inside Smurfette in that is
inside of that anonymous inner class which is this one on clique Meffert right.
So let's go inside this method.
So what we should do here what should I do here.
What I want to do here is always ask these questions when you want to actually write your codes.
So the first thing that you want to do here is to actually create an object of the hype Buxar class.
So let's actually just click on this box or telephone it here as you can see if you have a box or a
class with these instance variables as you can see.
Here we have actually this constructed.
And we have these getters for these instance variables.
So inside this main activity class are you able to create an object of pipe Buxar of tables at class
and I want to actually descent that specific object to the server.
So let's see how we can do that.
First of all I need to elevate the use it actually click on this button.
I need to create an object of type Buxar.
So let's actually create an object of a Buxar here.
So here I can say Boxer and the name of my object is Buxar assignment operator.
And here I just need to put the new keyword here.
So as you can see here first I just created a valuable type box.
Right.
And the name of many variables is boxer.
So you already know that variables are just placeholders for storing data values valuables in order
to store data and when ever I want to actually access those data I can just refer to the name of that
variable.
So here we have this body right here right and now I've put an assignment operator here and now I want
to actually create the actual object.
So whenever you put the new key word it means that you want to create an object so new.
And here I can say Boxer and here just select this upset and then press enter key on your keyboard.
And here it says that we have actually two constructors.
The first constructor is without no no parameters.
It is without any parameters as you can see here.
But the second constructor is this one which accepts an argument of types 3 and Buxar name.
So let's actually provide a name for our Buxar so we can provide a string value here a string literal
or as you can see here let me show you the emulator and as you can see we have these 80 texts.
So you want to get these values from are any texts or text fields.
So here I can say for the first argument I can't say EDT Boxford name dot get fixed dot two strings.
Right.
So this is going to be our first argument for our puzzle name.
The second argument is actually for the Buxar power.
Right.
So here again this is our edit text right.
So here I can't say EDT EDT box idiotcy punch power that's get text that string.
So this is our second argument and the first argument is this one punch speed.
Right.
So here I can't say EDT punch speed.
That's good text editor pun spitted get text that too strange.
So at the end of your statement put a semi-colon.
And now let me actually create a new line here so that you can see these values are better.
So as you can see here you are creating an object of type Buxar and this box class as you can see needs
of free arguments as you can see here.
This object needs a free values for free arguments for the first argument.
As you can see here if you need to pass a string value which is this one EDT box and in that get text
that was.
But for the second argument as you can see we have punch power which is of integer.
Right but we actually passed OSTLUND value.
EDT punch power that get text that restraint.
This is actually string value that we get from this text.
So here mean it actually an integer value not and not as string value.
So what's the problem here.
How we can solve this problem how we can actually convert it and a string value to an integer value.
So in order to do that here as a Can I just need to just type in here integer.
So before this value it is punch power.
Here are just the integer.
So here I am referring to the name of the integer class with capital.
This is very important.
And then here I just need to call a static method on this class.
So you already you are already familiar with the static methods indaba.
So here integer parts end.
So as you can see here we have this method parse it and this method parse and accepts an argument of
types 3.
So it's going to actually convert a string value to an integer value.
So integer that parse it.
And now we need to pass this thing value to this method parse it and then I need to put a close parenthesis
here at the end.
So this is our second argument.
And now we solve one of these problems and here we have our first argument as you can see here it says
again for the first argument we need to pass the punch speed because of that integer.
But we passed our string value.
So here in order to solve this problem again I can say integer dot parse it as you can see here.
Again I need to pass this string value to this method parse it and then I need to put a close parenthesis
at the end so hopefully that makes sense.
And now you can see that we created an object of type Buxar here and we passed these values as the arguments
of these Boxford object right.
And be assigned it is object to this Buxar valuable.
So now this box of valuable holds this box that object.
Right.
And now I want to actually send this Buxar objects to the set.
Right.
So let's see how we can do that here.
I can say database reference dots.
And here I want to actually create a child here.
I want to create a child.
Let's let me show you the web browser here.
I want to create a child and I want that child name to be actually a unique ID.
And then I need to I want to actually pass that object to that box that object to that idea.
I want to actually pass up the box that object as a child of that ID.
So in this way we can have multiple IDs with different backset objects.
So let's see how we can do that.
Let's go back to an android studio.
So database reference thot child.
So for the child I need to pass a string value right.
So here I can't say databased offense.
That's a push that's key.
So in this way we are actually creating a unique ID so database reference that push that get keyed in
this way we are creating a unique ID and then we are actually getting that value which is actually the
osting value.
By calling this method get key.
So in this way we can actually get that child right and you want to pass or box that object to that
child which is this idea.
So here I can say that set value Buxar semicolon.
So now we can actually pass our box object to the server.
So it's actually on our project and see what happens.
So now as you can see here our application is actually running on this emulator here.
So let me show you the web browser here and then let me show you the emulator.
So now let's actually create an abox that object and this sent that box that object to this error.
So let's specify the Buxar name.
So for example the box and it is a.
And the punch power is one handed and the punch speed is 200.
Right.
So now let's click on the spot and send data to server.
And now we should see these data here.
That's a little bit here.
And here as you can see this is our ID.
I told you that I'm going to actually create a unique ID and then we can actually pass that the box
that object to this idea or I can actually make that box that objects object as a child of this ID.
Right.
So we have this unique ID and he and as you can see this is our box of object with these values Buxar
named a punch power 100 and Dupont's speed 200.
So we have this unique ID and this box that object is actually a child of this unique ID.
Right.
So let's actually create another box set up to it.
In this this time the name is be the punch power is 10 and the punch speed is 20.
Let's click on this button send data to server and again as you can see we have another box up box that
object we can actually create another box object with these specifications with these values because
we have different ideas as you can see here.
Right.
So let's create another box set up to this time the name is c..
And the punch power is a 400.
And the punch speed is for example 90 and then click on send data to a server and he and as you can
see we have another box set object with a unique ID.
Let's create another boxer object.
So this time the name is D and the power the punch power is for 40.
And the punch spit is 900 and then click on send data to server.
And again as you can see we have another box object here.
Right.
So let's go back to our Android studio and now I will try to get these data here as you can see we have
these data here right.
I want to get all these data this and I want to show it here inside my emulator inside our takes view
that is actually the inside of a vertical scroll view.
So let's go back to our Android studio and here before the end in curly brace of this uncreate Smurfette.
So as you can see here after the Indian curly brace and after the end prentices hear of this up.
So thankful because of this button I want to actually just create an add value event listener for our
reference.
Right.
So let me show you the web browser as you can see.
I can actually create an add value event listener for this reference and then I can be notified when
the user changes.
One of these objects right for example the user wants to delete this object.
And then I can be notified.
Or for example the user adds an object to the database.
And in that way again I can be notified and I can show that data to the user.
So let's go back to our Android studio and here I can say database reference.
That's at value event listener knew.
So in say the prentices just put the new key vote and he had to just hold the shift key on your keyboard
and then press on the little key on your keyboard.
Value event listener and the Android studio is going to help you to choose this option and that person
entered on your keyboard.
And here as you can see after the end prentices just put a semicolon.
So now as you can see we have these two methods on data change and canceled.
So if you want to work with this on data or change my fear because whenever that user changes one of
these objects we can be notified.