Store Data in Firebase real time database in Android Studio - Android Firebase # 1 - 2020

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
assalamualaikum my name is the musa condor and today we are going to start our firebase tutorials inside the series we have just started so in the first video we have created our splash screen then sign in and sign up screens so now we are going to create our firebase tutorial inside our signup screen we want to store our data inside the firebase using the signup screen we have created recently so if you don't know how to create this design you can check the videos link in the description so now let me add a user which is John and it's user name will be John okay when I am going to click this Go button our value should be added inside the screen at the left side which is a firebase screen so click on this button and to add the values you can see our new user has been added which is the ID has double one double two with the values we have just added so this is what we will be creating in this tutorial stick together and watch the video till end ok first of all open fire based on google.com and in here click on this get started button there are basically two ways to add firebase in Android studio project the first one is the manual one which is not recommended and the second one is recommended which we will be implementing in seconds so the first one is click on this add project and you have to give the name of the project then you have to assign this package name inside the project and you have to do all the manual things you have to add dependencies you have to download the JSON file and add it inside the project and inside the app so which is not the recommended way okay so the recommended way is go to the tools and inside you have a firebase click on this and the assistant firebase assistant will appear and inside you can see we have a bunch of options so in this tutorial we are going to deal with the real time database because we want to store all data inside the firebase and in next video in the login we will try to fetch or try to login using the data we are going to store in this video you can also see how to authenticate using email and phone number in the next tutorials so if you are new you can subscribe to the channel for more videos click on the save and rooty button and in here you can see we need to connect to firebase so this is all automatic we don't have to add anything manually you can assign a name so in this case I am NOT going to change this name and you can select your result country and connect to firebase ok once connected to add real-time database in your app there are some dependencies when we click on this button you can see we have three dependencies the first one is in the project level and the last two at the bottom two are in app level so accept change to care these dependencies okay once dependencies added in the project can go to the examine or the design section close this assistant see we have bunch of fields here if you don't know how to create this field these are basically material design fields let me let me show you you can see this is material dot text field which is currently the first one is layout and inside this layout we used edit text and we assign the IDS to our layout not to over edit text so if you don't know how to create this design or if you new to my channel you can check my last video link is in the description or click on the right top corner let's go to sign up for the coding and in here I have already created all the variables these are basically text input layout not the edit text simply create them and we have two buttons I have created these folks as well when the user clicks on the registration button on the click of the registration button what we want is to store our data inside our firebase okay let's quickly open the firebase and in here you can see our project is created with the name of Buzz rent and in here you can see we have a database so for now we going to create our database of store values inside the database firebase provide two type of database the first one is the fire store and the second one is real time database both are very useful and both have some specific features but for the current project we are going to use the real time database so you can click on this create database and inside for the rules currently we are in the test mode do not launch your applications with the read and write true for the rules to avoid hacking or to avoid hackers to steal your data from your application so for now allow read and write we are going to choose test mode and click enable and inside the firebase you can see your security rules are defined as public so anyone can steal modify or delete your database so dismiss this you can change your rules in here as well ok our database looks like empty currently so the firebase works basically in a tree structure it is not like SQL or the structured queue languages with have some tables and relations so this is our tree structure you can see we have empty database let me quickly create one for you so you can better understand how firebase works ok in here I am just added a few fields of firebase values you can see we have a top node which is called instance in firebase and we have two bottom notes which we can be reference from the word top node you can easily see in a minute when we will be coding so first of all inside our project we need to call this instance of firebase and inside this instance we can easily get these references so inside the first reference when we write dot reference in our code which means go to this instance and inside that instance go to this reference which is called courses and in that we have a bunch of values but currently we have the course 1 0 1 which is called computer science and its course ID and some other values and inside the second reference which scored users we have two values the first user where they have some name and some other fields and the second user also have some name and some fields so this is how our data structured inside firebase you can better understand this when we will be creating our application so open Android studio okay start coding let me create these variables which is called firebase database and let me call it root node to make you understand and then we need database reference and the reference will be a reference to sub nodes of our loop node or the sub elements of our root node for we need to firebase database and then database reference so what the root node will do which is firebase database will call the firebase database root node which is equal to firebase database dot get instance as I told you this get instance will be calling to the root node which is here at the top it includes all the database of our firebase of our project it will include all the database or all the elements inside our project to call the specific one which is in this case is a courses or to access the all the fields of the courses or to access all the users we need to define the reference so for the reference we can either define it in the first line or go for the second line we have defined the reference variable at the top which is equal to root node which is our database dot yet reference and inside this gate reference we have to define which reference we want to call in this case we have the reference of users right users in here okay to set value inside our users what we can do is simply call the reference and dot set value and inside the set value whatever we will pass will be stored in our firebase database it is that simple okay let's run it and see what will happen open the fire base okay what we want is to when we click on this sign up and inside the sign up we have a go button okay when we click on this go you can see our data change and we have a message of users which is first data storage spelling mistake sorry about that and open the Android so this is it for the example so now we want to move toward our registration for the user so to add our registration first need to create helper class which will store the data of our users so go to the Java and inside the first folder create a new Java file if it use a helper class and click OK once this is added we need to add a few variables all the variables we want to store inside our database so go to the design and in here we have 1 2 3 5 different fields with full name username email phone number and password let's quickly add them inside the Java class add all the variables and right click go to generate to generate our constructor and Gator setters click on this constructor and highlight all of these click OK for the firebase to avoid errors we also need an empty constructor so again go to generate and create a constructors which will be the empty one simply remove this okay we have empty constructors and the next the last thing is we want to add ghetto setters for all of them because we are going to use these later on in the project okay we have our ghetto setters and our constructor is ready so simply close this user helper class and in here after the reference we need to call our new class which is user helper class and name it and inside that constructor we need to pass all the venues which we will be getting from our fields so the first thing is we need to get all the values from the text fields let me click create them okay let's run it again okay insert the sign up let's add the values again password click on this go and open our firebase you can see we have email we have name password phone number and username okay now we want to do is we want to add more users first one to assign it's ID ID of the user of the first user and then second user and then third user and then we want to add all these values for each users so for that we need to add child and inside that child we want to set all these helper class values so that child can be UID can be a single value you can generate your own or this case we are going to use phone number do not use email for the unique values because email have some innovated characters and for the path of firebase firebase don't allow these values like at the red dot etc inside this path and this will be the path of our project so let me show you run it again open the firebase okay in here add some values and phone number should be unique click on this co button now you can see we have a new user with the phone number of its ID which is one two three four five six yet and when we click on this plus icon you can see we have all these fields of this user so we can add as many users we want but with the same ID we can overwrite these values so we will do the update later on so for this tutorial open Android and you can see we simply get these values from the fields we have created our helper class and in its constructor we pass all these value you want to add inside our database then we assign this reference which is the user we want what we want here is we want to add our users inside this reference we tell the code that go to this users which is in the reference and inside that user create a child with this phone number and then set all the values of this child over the firebase okay lets me if we change them something else username should be same but we want to change the ID which will be one two and click on this button again to add another value you can see we have another ID with all the values will be this these values are different from the previous values and by this way we can add as many users we want and in the next video we will get these values and login our user inside our application okay that's it for today's video see you in the next video stick together if you have any questions tell me down below in the comments if you learned something new please like the video and if you are new to the channel subscribe the channel and hit the bell icon for more videos thank you for watching take care Allah is
Info
Channel: Coding With Tea
Views: 207,789
Rating: undefined out of 5
Keywords: firebase android tutorial, firebase tutorial android, firebase tutorial, insert data in firebase android, firebase android studio, firebase realtime database, firebase database tutorial, firebase in android studio, android firebase, firebase realtime database android tutorial, android studio firebase, firebase android, firebase authentication, firebase authentication tutorial, firebase authentication android, store data in firebase realtime database in android studio
Id: wa8OrQ_e76M
Channel Id: undefined
Length: 16min 15sec (975 seconds)
Published: Mon Jan 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.