High students in this theater are we going to go ahead and create another Android application that actually
connects to the firebase in order to retrieve data up from the server.
So let's create an android studio project.
So just click on this start in your Android studio project and then for the application name just a
pin here app 6 the free dash retrieving data from firebase.
And here you can specify the company domain package name and he can specify the project location and
then click on next and here choose Apr. 19 Android 4.4 chitchat for the minimum scaped for phone and
tablet and then click on next.
And he had to choose the activity next and he had to change anything.
The Actually the activity name should be main activity and generate lay out foil as you can see here
lay out name should be activity underlined main and it says back for backwards compatibility apcupsd.
So make sure that also text box is actually checked on.
And then click on finish.
So now as you can see here it's going actually create the project for us.
It's going to set the project.
And now as you can see here the project is actually created.
So now let me actually close this window here and now.
First of all I need to actually connect my app to death firebase.
So in order to do that let me ask you to open my web browser.
So here as you can see I opened my web browser and I actually entered this you are elde firebase that
Google dot com.
I am actually guided to this page and here as you can see you need to be signed in into your G-mail
account.
And then here you can actually click on this go to console here click click on this go to cancel.
And now let's actually open our Android studio here.
Just click on Tools.
So make sure that your Android studio is actually the latest version of Android studio 2.2.
Right.
And then click on Tools and then here click on firebase.
And now as you can see here just click on these real time database here and now click on Save and retrieve
data.
So first of all we need to connect our application to the firebase.
So here click on this button connect to fight fire race and then it's going to actually start connecting.
The application is set up.
Number the free retrieving data from firebase to the firebase database.
So let's actually wait a little bit here.
So now here is the window opened.
OK.
And it says create new firebase project.
So here click on Connect to firebase.
And here we should wait a little bit and here at the top it says Firebrace connecting app to Firebrace
right.
So this is actually a message that's that the Android studio is showing us.
And now as you can see here it says connected.
Right.
So now here we need to actually just do this second step.
And it says at the real time database to your app.
So just click on the spot in here at the real database at the realtime database to your app.
And here this window opens and then here you just need to click on accept changes.
And again we should actually wait a little bit here.
So now as you can see here everything is ready.
Right.
So now let's actually close these assistant here.
So just click on this panel here assistant and now this assistant is actually collapsed.
And now we can see our job codes here.
So let's actually click on this activity under line made that example here and double click on the top
here.
So now we should actually design the user interface of our application.
So first of all let's actually delete this whole over text view here.
So just select it and then person delete key on your keyboard.
And now let's actually open the browser.
So here let me actually just refresh this page.
So just click on this refresh button here at the top reload this page and now it's going to show us
the project that we created here.
And we actually connected our application to this to this project.
As you can see it says about 60 free retrieving data from firebase.
So as you can see here we can't actually see the letters here.
So this could be for example maybe it has some limitations regarding the name of the project.
So let's just click on it and now as you can see here the project you can see the panels here.
And let's actually click on this database here.
The database panel just click on it and then just click on the rules tab here.
And we should wait a little bit here in order to see the rules and here as I told you earlier we should
actually make these are just exclamation marks equal operator to equal equal operator so that other
users that are not authenticated to this application can be I can actually use this database and then
we can publish and now it says rules published.
Right.
So now let's actually go back to our data type here specifically can this data tap and now we can actually
interact with this database.
So first of all let's actually go back into our Android studio and now let's design the I actually use
an interface our application.
So here let's actually drag our linearly out vertical into this relatively out here.
So here inside this pallet section is actually just scroll down here as you can see we have these layouts
folder.
So now just select is linear linearly at vertical here and distracted here and put it at the center
of this relatively out here and now let's actually drag an edit text into this linearly at vertical
so inside this takes fields folder just select this plain text here and write it here and put it inside
this linearly as vertical and now as you can see the idea is Eadie text.
So let's actually delete this ID and change it to eat it he she EDT key and then press on until key
on your keyboard.
And unless I actually delete this takes the value of this text and then just present delete key on your
keyboard and they hitch it just for the hint.
Attributes just like in here.
Dot dot dot and then press on Enter key on your keyboard.
And here just select the state's view here.
And for the ID just type in here th the value and then present Enter key on your keyboard and then lets
actually did it.
This takes you here for the text attribute.
And now let's actually write another Potten into this linearly at vertical so in inside these widgets
father.
Just select this button here and put it here inside this linearly at vertical and below.
This takes you here and for for the ID to step in here between and get data from server.
And for the text just typing here gets data from server and then person until 3 on your keyboard.
So now let's actually go inside our main activity the java file here and here inside these uncreate
Smurfette Let's actually just create some objects that actually to be fair to the user interface objects
that we have inside the user interface.
Right.
So now let's go back to our main activity that java file here.
And now let's create these objects here.
So the first object is going to be an edit text suggests they've been here edit text and the name is
going to be EDT key assignment operator and an entity which has this object to an edit takes object
find view by ID or that Id dot EDT Keat and then put a semicolon at the end of your statement.
And now let's actually create another edit edit subject.
EDT.
Value assignment operator.
And then this actually has this object and it takes object find view by ID or that Id dot EDT value
and then put a semicolon at the end of your statement.
And now we need to actually create an object of like button.
So Potten PETN a send data to server assignment operator.
And here I just need to cast this object to an editor to and actually Potten up to about an object so
putten find view by ID or that ID that PTEN as send data to set right and then put a semicolon at the
end of your statement.
And let's actually create a takes few objects takes beauty XTi value assignment operator and then let's
actually cast this object to our Takes objects so takes you find the way Id are that Id thought X the
value and then put a semicolon at the end of your statement and define on a variable that we should
create here.
That can actually hold a value of type but it is actually in PTA and get data from setter and then put
a semicolon here and then put an assignment operator here and here let's actually cast this object to
a button object find view by ID or that ID that PTEN gets data from set and then put a semicolon at
the end of your statement.
And now let's actually create a firebase database here.
So.
So just type in here firebase database and the name is going to be firebase database assignment operator.
And just again referred to the name of this firebase database that get instance if it here as you can
see Firebrace database that get instance in this method get instead this is going to return an instance
of the database.
So now if I show you the web browser browsers you can see here we have this instance of the database
here.
So in this way we can actually get this instance and now that we have access to this firebase database
instance it's actually a reference to our firebase.
Right.
So here I can see database reference.
So as you can see here now we can actually get a reference to the database inside the Firebrace right.
So databases are friends and the name is going to be database reference assignment operator.
And here I can defer to the name of this firebase database instance.
So firebase database instance that get reference or I can see you get a reference from you model or
I can say Get reference here.
So are here I choose this one get reference here or I may want to choose good reference from you at
all or maybe this one gets reference and then put a semicolon at the end of your statement.
This gets reference Smurfette here is going to return to the instance of the firebase that we have here.
Right.
So he's going to give us this actually this instance and now I can actually just write some data to
the database by writing for example a database reference dot and here I can actually create a child
for this instance or I can directly set a value to this instance.
So this actually just test this one set value.
And here I can say some value and then I put a semicolon at the end of my statement.
So now let's run our project.
And now let me show you the web browser and let me show you the Android emulator here.
As you can see now we have access to this of instance to the instance of our database.
And as you can see here we provided a value to this for this instance some value right.
So let's actually just delete this line of code here.
Now let me actually go to the browser and here just click on this delete button here and then press
person delete key on your keyboard.
So Nancy as you can see here the value is not right.
So let's go back to android studio and now I can say for example database reference dot child for example
the child could be a child.
And here I can say that said value.
And here I can assign some value here for example value and then put a semicolon at the end of your
statement.
So now let's run our project and not now.
Let me show you the web browser here.
As you can see here now this database instance has a child and of value right.
So hopefully that makes sense.
So let's go back to android studio.