So now are we to actually create our difference to our database in firebase.
So how we can do that.
So in order to actually learn how to actually send data to the database in firebase First we need to
actually read the documentation.
Right.
So let me actually open the browser here and here.
Just click on this overview here.
OK.
Or you can actually click on firebase or you can actually just open another tab and then go to the firebase
website.
So here I'm going to click on this or that of you here and now as you can see here we have these actually
these tutorials and these are actually the documentations that we can use in order to learn to actually
work with the firebase.
So because we want to actually work with the database as you can see here we have this database here
and it says store and simple data in real time across all connected clients.
So here just click on this little more here click on it.
And now we are guided to the documentation.
Right.
Or I can actually click on this firebase here at the top left and then as you can see this is the virus
Web site.
And now this is actually the initial page that is going to be shown to you when you actually open the
file by Smith firebase website.
And now at the top you can see it says Ducs right.
I can click on the stocks here and then as you can see here we have firebase firebase by platform and
then here just click on this get started.
Got it.
And here as you can see this is actually firebase documentation.
And now as you can see here we chose Android.
Right.
And here click on these real time database here and then click on get started as you can see here.
Just click on this get started.
So realtime database Android gets started right.
And then here it says that you need to connect up to firebase.
So we already connected up to fire rates and we add the he added the real time database to our application.
So as you can see here we actually configured the database rules.
OK.
As you can see we actually can figure out the database tool.
So let let me open this tap here and if I click on this database here and then if I click on the rules
tab here you can see that we actually configured the database route.
So we actually allow the users that are not authenticated to use this database.
Right.
But using this double equal operators here.
Right.
So let me ask you to open this up here again.
And now it's time to write data to the database.
Right.
So now it says that to retrieve an instance of your database using to get instance.
So first of all we need to actually get an instance of our database.
This is the first step and reference the location you want to write to.
So first we need to get the instance.
And then if we need to actually get the reference to the location we want to write to.
So let's see how we can do that.
First of all as you can see there is a comment here and it says write a message to the database.
Right.
And it says firebase database.
So here it is actually creating a variable.
And the name of this variable is database right.
Did they touch type of this variable is firebase database and then it put an assignment operator here.
And as you can see here it actually referred to the name of this firebase database here firebase database
that instance.
So it actually refers to the name of this firebase database class and called the Smurfette get instance
on this class.
Right.
So in this way we can actually get an instance of our database and we can assign that instance to our
variable which is of type database which is of type firebase database and its name is database so these
database here now holds an instance of their firebase database.
So let's actually first of all let's just copy this line of code here.
And let's actually open the Android studio and now let's actually first inside these uncreate Mefford
we can actually just paste this line of code here.
So now as you can see we have actually an instance of the firebase database.
So this is the first step.
Right.
So now let me create a comment first so that for writing data to database.
Right.
So this is the first step.
And now let's actually open our web browser again here.
It says that we need to actually get a reference here as you can see we need to get a reference to the
actually location that we want to write to.
Right.
So now let me actually open this tap here.
Firebase concert and click on the state tab here as you can see.
And now as you can see if you have this up actually this is our fiber's instance right.
And we just want you to get a reference to the location that we want to write to.
So first let's actually open these tab here and now as you can see it actually created a variable of
type database reference and its name is Mailer.
And then it put for an assignment operator here and then it referred to the name of this database instance.
So database that gets reference right message.
So first let's actually go inside our Android studio and now we want to actually get our reference to
the location that you want to write the data.
So the data type is going to be database reference as you can see here right.
So I can just type in database reference and the name is going to be my ref.
As you can see here so that the same name here you can actually name it up in other names.
You can actually give it another name but I chose this name here myself and then I put an assignment
operator here.
Right.
And then I refer to the name of this database instance that I created in number 25 dot.
So now you can see here we have some if it's right or you want to choose this method gets reference
from you l right through a fence.
So just select this method here and then person enter key on your keyboard.
And now inside Apprentice's as you can see it says that we need to actually put on not Knol screen value.
So we need to put up two double quotes here.
And inserted double quotes.
We need to put a u r l.
So what is that you are less actually open the web browser again.
And let's click on this tab here.
And as you can see here we have this.
And here.
So just click on it you are here and let's click on it and then click on copy right.
Or if you are using a Windows machine you can actually hold the control key and then press on the letter
c key and your keyboard.
And if you are using a Mac you can actually hold the comment here and then press on the leaders key
on your keyboard and then now that we have actually copied this you Arel It's actually open the Android
stood you again and inside double quotes.
Just paste this value right and then put a semicolon at the end of your statement.
So now we actually got a reference to our location that we want to write the data and that location.
Is this actually this you are.
All right.
So now if I click on this you are on here and if I actually for example add another radio for example
person persons and they can go as you can see now it says that we have inside this database.
We have this person's right.
This is the location that we can actually write our data.
Right.
So now let me actually just delete this persons here and then click on go.
So here we have this instance box 38 or dash C 59 D-B colon null.
And it says The value is null.
So this is the key as you can see here.
Disvalue is the key and this value is that we have no value right.
So now if I click on it nothing happens right.
So as you can see here we have this plus button.
And here we have this delete button right.
And if I actually hover over this plus button here it says add child.
So let's click on it and now it says that you can actually just create a name of value.
So as you can see here let me actually click on this delete button here delete button here and now if
I click on the plus button here it says that we can actually add a child to our database instance right.
So now if I actually click on it we can actually add a child so what it's going to be the key.
So the name is going to be for example the name is going to be box or name.
Right.
And I must actually put a value here.
So the value can be for example.
So now let me add this extra W so the value can be for example my Buxar.
So this is the name right.
This is the value.
And if we click on this ad here now we have a child here.
And it's key is box name and it's value is my boxer right.
I can actually create another child as you can see here.
I can actually create an adult child here.
So if I click on it and here I can say for example Boxer for example power and the value can be for
example of one thousand or ten thousand and click on.
And now we have another child as you can see here and it's in it's KEAYS box of power and its value
is ten thousand.
Right so now as you can see here the value here is of type string.
And the value here is of type integer right.
So now if I click on this up plus here and now I can actually create another category in order to hold
the kickboxers.
So for the name I can just type in cheek boxers right.
Here.
I don't want to assign a value because this is going to be a category that I can actually contain the
values of the kickboxers.
So and here as you can see we have this A-plus right.
Just click on it at child and now as you can see here we have a category that can actually contain the
other values.
So for example teach boxers and the name is going to be for example that she is going to be kickboxer
name and the value can be the value can be for example my Keech boxer.
Right.
And then I can click on that.
So here as you can see we have actually another chapter called The kickboxers that can actually hold
this child kickboxer name.
And this is the value.
And in this way we can actually create lots of children and lots of parents.
It doesn't really matter how you manage the database it just depends on your own actually a way of structuring
the database.
Right.
So for now just look at this structure as you can see we can actually say we can do the same thing that
we did here from our Java code inside our Java code by writing Java code so we can do the same thing
here.
So let's see how we can do that first.
Let's actually delete these values here.
As you can see if I click on the delete button of window opens and then you can actually click on it
and then there's actually did it this one and then delete this one right.
So now we have only this instance right.
This is going to be the patent.
And now this actually you can actually call this also a root.
Right.
Let's actually go to our Android studio.
So now that we have actually an instance of type database and now that we have a reference to actually
did the location that we want to write the data.
Let's actually open our web browser again.
And let's actually open this.
Let's actually just open this tap here again and now it says my if so this is the first step might if
that set value.
Hello voting.
So now let's actually copy this line of code here and let's get you to go inside our Android studio.
And inside the unclick listener of this button I want the data to be returned to the database when the
user clicks on the button.
So inside the uncle listen of the database as you can see here in say the uncle Smurfette of there is
unclick listener I can just paste this value.
So now as you can see here we have actually an error and it says valuable myself is accessed from within
Inul class needs to be declared final.
So here we can in line number 27.
We can actually declare this valuable as final so that we can actually make it a constant.
Right.
And now as you can see here the error is gone.
So now let's actually run our project here initialising AEB.
And then you can actually choose the virtual device and then click on OK.
So now let's wait.
So now as you can see here our application is actually running on the emulator.
So now let me make this emulator actually bigger.
We're just trying to get here.
And now if I click on the spot in here send the data to say well let's actually click on this button
and see what happens.
Just click on it and now let's actually open our web browser and then just click on this tab here and
now as you can see here we have this key which is the location that you want to light that data right.
So as you can see here we chose this you r l as the location that we want to light it up.
So when I actually go to this you are well we actually guided to this actually the page to this instance
and it we connected the right value to this parent.
So this is going to be the key and this is going to be the value.
And here you can see that we have this key and the value is Hello world.
So now if we you to go to the Android studio here I can show you that first.
We have a reference to their database instance.
And then we have a reference to the location that we want to write the data.
So this is the location that actually got us to this page that is valuable to this instance.
And then when I say my left right might it refers to this instance right.
Might have that set value.
Hello world.
Here we are setting the value here right.
Hello world.
So this is just a simple application right.
We're going to actually make it more complex.
But for now I just want you to get the idea right.
And if I actually go to the open this tap here and as you can see we are just here right to your database.
So now we want you to make it more complex.
Right.
So now let me actually just close this tab here and now we have this value.
Let's actually go back to an android studio and here instead of hello world as you can see here are
you going to actually put the value of these it takes to the set.
So just delete this hello world here I just referred to the name of this EDT value dot get text dot
2st so we can actually assign a think value here right.
Because this sets value here.
Let me actually just again refer to the name of this might have thought sets value as you can see it
is set value needs a value of type Object.
And this thing value can be actually an object right.
So let's actually run our project now and let's wait a little bit here.
So as you can see here our application is actually running on this emulator.
So now as you can see if I click on the spot in here let's see what happens send the data to server.
And let's actually open the browser here and now as you can see here we have an empty value.
Why.
Because we haven't actually assigned a value to this edit text so let's actually write a value here
inside this as it takes.
So here I can just typing proxying is a martial art.
Right.
And then click on send data to server.
And now as you can see it says boxing is a martial art.
Right.
So it is actually sending this data that I put here to the server.
So let's go back to what Android studio
and now I want to actually make it a little more complex.
So let's actually go to activity underline minute example.
So here we need to actually make a design to use an interface here again.
So let's actually just select this button here and then press on delete key on your keyboard.
And then here we can actually say this componentry section at the bottom left here.
You can actually just say this componentry section it can select this editrix and then press on delete
key on your keyboard.
So now we wanted to design the user interface here again.
So let's see how we can do that.