How to Retrieve data from Firebase Database in Android Studio Retrieve data from Firebase in Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
assalamualaikum my name is the musa condor and today we are going to fetch the data from firebase in our android tutorial series inside our profile section and after validating the username and password we will move our whole data or the data of their specific user to our login screen so let me show you okay inside the username write the mood and the password will be the one we have created you can see we have a strong password and the username cannot have spaces etc so click on this poor button and this loader will still loading until our authentication authorizes we have user name at the top then we have our name then we have a username and full-name email password and phone number okay let's go back to the signup screen for the validation so when you click on this KO button when the fields are empty you can see we do not have a scroll bar our fields are empty and we have some errors and write some username and we have still the password error and write some password our values fetched from the database with no such user exists and also if there is a user with them we have just logged in click on this KO button and we have wrong password so this is what we are going to create in this tutorial so and if you don't know how to design any of this screen you can get the video the link is in the description or you can go to my youtube channel inside the sign up we have email and phone number so in the next video we are going to validate first the email by sending email to the users email and before directly signing in the user inside our or registering the user inside our application so after the email we will also go for the phone number verification will send SMS to the users mobile and for this tutorial we are sticking to our login screen so let's quickly see how we can do that ok to get started open the login screen and as you know we have created the validation forms in addition username and password and all other fields inside the signup in last video so for this video we are going to continue it so inside this login user we are varied adding username and password first of all open the username inside this username as we were validating for the signup we do not need username to long and white spaces are not allowed inside our login screen so these are for the signup make sure that user do not enter the wrong values so when the user already entered the values so we just want to make sure that the field is not empty and once the error is gone username should set the null okay once the error is gone we want to remove that error so we pass null inside set error and after the error is gone we want to remove that extra error space as well because this is a material design so we will set error enabled false so it will also shrink back our design to its original position and we also do not need this open the password field and remove this line and also we do not want to save your password is too weak but instead we want to check if this user has the same password he entered so for that we are going to first validate the username and password if they are empty or not okay once we have very rated of a username and password what we want to do is to we will simply write else and inside we will create another function which will simply check is user what this is user will do is to fetch the data from the firebase of the specific user and check that if there is some users related to this username entered by the current user and also matches its password from the firebase so create method is used in login screen and inside this is user we first need to get the user interval use inside string control D to duplicate and user entered password change it to password here we have user in third values username and password so to start working on the firebase we first need to create firebase reference so call the database reference which will be the reference is equal to firebase database dot get instance dot get reference and inside this reference I am going to pass users as you can see inside our firebase we have the first instance then we pass the user as the reference which is called users you can see we have the reference which is users and the instance you can see we have the instance go to the firebase database and go inside the instance and which is the parent node and inside we have a reference the name uses so now a reference is pointing to the users we want to add the Curie which is the first one with firebase tour database curie check user is equal to reference means which is pointing to our users all users dot order by child and we want to order by child means search for the keyword username dot equal to a username entered by the user so what this query will perform is an inside look for the username for all the users and match it user emitted by this user so if we have this username we can check it check user dot adds lister for single value event you can also add these below two functions as well but for this tutorial I am using a listener for single value event and in here we're human listener so you can see by default we have two methods on data change and own data cancers so in the on cancer we have the error methods we are not working on this currently but we want to get this data inside of our own that a change method our data is inside this data snapshot we first need to check if there is some data inside this data snapshot dot exists and if there is data inside this data snapshot we want to get that data inside the string password from database is equal to go to the data snapshot dot child and this child is basically the username which has the same user name entered by the user inside our database there is AI username entered by the user so we will simply get user entered username so go to this user name dot child and get the value of that username which is password don't get value and as we are storing in the string so converted into string dot class if there is a username matches to this username entered by the user inside our login screen edit text field so if there is a user that means we have some value inside our data snapshot and if the data snapshot exists we will face that password of the specific user having this username okay once we have this password what we will do is we will simply check if password from database dot equals to the password entered by the user user interface word if they are equal this means that user entered the right username and the right password so what we want to do is to login to our user profile and share all this data or user profile so once this is authenticated our user input right username and password we first want to get all the fields the firebase change it to name make sure they are matching exactly like we have written inside here so we have a name email password phone number and using it's only n is capital for the phone numbers press control D to duplicate so but this way we fetch all the values inside our these variables we already get this password so we have five values so to pass it or to call the next activity right intent is equal to the new intent and go from this application to use a profile application or class or to calling this next activity we will first add intent dot inside this protects extra you can see we first able to find the name of that value and then the value itself so the first one with the name and that name will be named from database so by this way we can add as many values we want ctrl D to duplicate the line and change the value okay once we initialized or put all the data inside our intent then we will simply start over activity and past the intent in it okay if this is not the case so if the password went wrong we will move to the else section and call our password field passports set error and that error will be wrong password and what if our data snapshot does not contain any data that means there is no user there is no such user entered by the username inside of our edit text so if there is no data inside the snapshot what we want to do is to write user named or set error and this time the error will be no such user exists and we also want to add password dot request focus so this request focus will automatically request the focus and start pointing on that specific field and also in here before calling the next activity if the user second time entered the right value means if there is some data inside the snapshot means the username exists so we also want to remove that error from there so user name dot set error and inside this pass null to remove that error and also to remove that error line or the error space left inside our design write user name dot set error enable false so this is for the username also if the password went true we want to set this as well and call our next activity okay for now we're cold is pretty much ready so let's run and see what we got before running you have error here which is it should be username because we want to validate this username okay let's run the application we have a error before running application we need to pass a username not the password sorry for that because want to check this username should be equal to the username metered by the user I haven't seen this sorry for there so let's run the application I hope so there is no mistake ok inside this login screen first of all click go and you can see aware error fields are appearing it cannot be empty you let's write something in it and also for the password those errors are gone and you can see no such user exists after the validation from the firebase so let me check the values from the firebase we have a user's called ABCD and wrong password that means we were username is working and the password is Jie h and 1/6 and yes our username and password is working ok now inside this profile screen what we want to do is we want to show all the data of that specific user in here so let us quickly do that as we just pass the data inside our intent and now we want to receive the data inside our profiles which is this user profile so first of all we need to create the hooks and user design first of all we need to create these hooks as we already assigned their IDs so let me click create these hooks and ok we have created all the hooks and in here we will create a function show all data and that function name is also be show all user data simply click on this bulb to create the method inside this show all data we will simply get the data from the intent get intent press alt enter two importance libraries and inside this intent right we need string values string user underscore username is equal to intent dot get string extra in here we need to pass the name of the string we send from the login screen which is name username email phone number and password username controlled you to duplicate five times username to name then we have email phone number and password if you don't know how to send multiple data you can check the video link is in the description we have all this data and to shut the data on the text fields we will simply write full name full name label dot set text and in here we will simply pass this user underscore name by this way we can set the data simply duplicate and set the data on all the six places [Music] okay we also assign that down the text field so let's run it okay we successfully get all these values and place them inside our profile you can check that inside the firebase we have the user with the ABCD username and then it has a phone number five six four then the password the name full name is inside our edit text fields and also on the top profile and then we have a username ABCD just beneath the full name so let me create a demo go to the sign up and first of all delete all these values from the firebase okay as you can see our database is completely empty so let me quickly add first username five and this user name is too long we have a 15 characters condition so let's add it and in here you can see we have our users and inside username is a mood and we have a detail okay let's go back to our user screen and inside this user screen we have username which is the mood and the password is 1 2 3 4 5 and click on this co button and you can see we have all these values we fetch from the firebase their full name then I user name then we have all these text fields so in the next coming videos we will be very dating or we will update our data inside of our firebase when the user clicks here and many their data so that's it for this tutorial if you learn something new please like the video and if you are new to the channel subscribe and more such videos will be on your way thank you for watching take care a la face
Info
Channel: Coding With Tea
Views: 91,445
Rating: undefined out of 5
Keywords: retrieve data from firebase in android, fetch data from firebase, retrieve data from firebase, firebase database tutorial, retrieve data from firebase in android recyclerview, how to retrieve data from firebase, how to retrieve data from firebase database in android studio, retrieve data from firebase to recyclerview, retrieve data from firebase android studio, retrieve data from firebase realtime database in android, retrieve data from firebase to listview, get data from firebase
Id: eGWu0-0TWFI
Channel Id: undefined
Length: 18min 58sec (1138 seconds)
Published: Thu Feb 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.