How to send data to the Firebase Realtime database. Android studio Kotlin.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to the second video of the Firebase tutorial in this video I'm going to show you how to take the data from the user and transfer it to the Firebase real-time database in the last video we have sent this sentence to the database and uh now we will go one step further okay for this video you need to know about the navigation component and you have to watch the first video of this tutorial uh then come back here to address I will put the link of them down below in the description and also you can click on this I button information button here on the top and watch those videos okay let's uh go to Android Studio here in the main activity uh we don't need this code I'm going to delete them and we don't need anything regarding to database here just the viewpoint okay I'm going to visit this okay let's go to the resource manager to the navigation create the navigation graph I'm going to call it my nav okay we should wait until uh the dependencies or Into The Griddle file and become scene then we can use this part foreign [Music] foreign [Music] we need an ID for it and let me change it to fragment fragment container view that's good [Music] layout V match parents layout and that's it here okay okay I don't need anything extra here uh let's go to the main activity here I'm going to write some codes to connect the action bar to the navigation driver and then we are going to each of the fragments the label will be changed based on that break okay yeah you're going to find love controller and it will be on content review and then the next line is configuration equals to here we need that the fragments but we are going to use but now we have only two fragments the home fragments and the add date of right so r dot ID Dot uh comma r dot ID Dot add brightness okay and now we have to connect these two together of action bar with navigation form we are passing the map controller and the app version and now let's play let's go to the uh project here I'm going to change it to Android Mode app Java and the Chrome flight I have added the a floating action button to the layout of this fragment now I want to write the pattern click listener for this button and then we are pressing it we should go to the uh add fragment okay I'm going to use the view binding here as well so uh private variator underscore binding is a type of fragment [Music] home binding question mark equals to null and private private variable which can be exactly binding get equals to understand binding and check then here underscore binding equal to right command palmbinding dot inflate and inflate insulator then container and what okay and instead of this Twitter binding dot oops when we don't need this question mark we can write here our so binding Dot and add button that on the listener and you want to go from this fragrance to the earthquake so find map controller dot navigate of the ID log action on fragment to the ad fragment this one and that's it if you don't need anything else here and let's go to the add fragment I'm going to copy and paste everything that I wrote in the home fragment regarding to the uh view winding here to make it short [Music] instead of this fragment add and I should import and here this thing [Music] add and yeah we can binding Dot like now here I have to uh create a variable for the database so private relating it radiator and I'm going to cut it fires base reference with paper data based reference and here we have to insulate [Music] so on your face reference equals to uh Firebase database dot it instance Dot get reference and I'm going to call it contacts okay and now we have a button here in the fragment activity and I called it uh send button so we need binding Dot and button dot that on click listener and whenever we are pressing this uh we should send the data so I'm going to create the function to do the activity here we have to take the data from the edit text so I'm going to create two variables here let me Zoom a bit yeah equals to binding Dot effect name dot tag dot this thing and phone number equal to binding the dot on the big dot okay now we have to store them into the data class so we have to create this data class here I'm going to right click new and view the package and I'm going to call it models and inside it I'm going to create a cutlane data killer and I'm going to call it contact okay here we have to create some variable so we need one ID with the type of string we need [Music] a value for the name again type a string and a value for the phone number string again and we have to write question mark and make them nude at the beginning okay that's everything for this class let's go back and here into the ads fragment uh I'm going to check them so if name Dot is empty [Music] binding dots this name Dot error equals to write a name and the same for the phone number thank you okay then Firebase weapon dot now I'm going to make a child not directly set the value so this one and this child should be uh a variable that we have to create it and for this I need two values here so first contact ID equals to Firebase reference Dot push and that key and this line will create a unique ID for each of the trials automatically and we need this ID later then when we want to do editing on this specific child we need the unique ID and then this is the child name and now we have to put the like taken data into this class through this line of code [Music] the class contact and you are passing the date to contact ID and the import filler [Music] then the name and then the the oh no let me check the order ID name and phone number yes ID name and phone number and now I'm going to pass this context into the chart it's here sorry sorry I made the mistake here I have to pass their contact ID here [Music] all right okay after creating the child we are going to set the value and I'm going to pass the untag this one here okay after setting the data into the Firebase and sending it we have to check if the if correctly received to the database or not so dot add on complete listener and I'm going to write a post here context foreign [Music] check so add [Music] on trailer listener the same I'm going to copy this line of code and paste it here and checking the error error dollar sign ificance here you can use this it I'm taking the error message and displaying this message into the post okay everything is set let me [Music] okay the app is launched I'm going to press this we are into the next fragrance and a name it can be Mac and the phone number any random number and I'm going to send it and data is stored successfully and here I have the child contact and opening it now I have the unique ID here I'm opening it and here I have again the ID the name and the phone number and if I delete them and press send data I'm getting error here I have to write something but still I have the empty data here stored because uh here in the data class I make them no and if we don't do this we will get error here and the error message is the same as the thing that I wrote here write a name or write a phone number and I'm going to write any other name Julia and random number and then and here you have it okay that was everything about this part of the tutorial and in the next video I'm going to show you how to retrieve how to fetch the data from the database and display it here in the home fragment in recyclerview if you are satisfied of this content give me a thumbs up please if you haven't subscribed the channel yet please hit the Subscribe button and hit the Bell Button as well to be aware about the new video thank you very much
Info
Channel: MkrDeveloper
Views: 4,887
Rating: undefined out of 5
Keywords: send data to the firebase realtime database kotlin android studio, firebase realtime database, firebase android studio, firebase tutorial, sending data to the firebase android kotlin, insert data to the firebase realtime database, firebase kotlin android studio, firebase kotlin, firebase 2023, android studio tutorial, kotlin, MkrDeveloper, mohsen mashkour, android, android studio, realtime database firebase, firebase, how to use firebase in android studio kotlin, navigation component
Id: 3XiZF1UBn50
Channel Id: undefined
Length: 25min 42sec (1542 seconds)
Published: Tue Mar 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.