Xamarin Firebase Tutorials - Save Data to Firebase Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so welcome back to this tutorial series in a long video we are able to set up our impure dialog fragment so I'm gonna pull up the emulator so that I will show you exactly what we did in the last class just to refresh your memory so this is an app so if we click on this Add button we are able to have this impute fragment you know this will actually help us to you know save our data to firebase so we designed this layout and setup this fragment and also we set up this material spinner that we have here okay so this is what we did the last class now in this class there is a couple of things that we are going to be doing so firstly we're gonna learn how to set up firebase in our app so we're gonna download the packages and we're gonna install it in our app and we're gonna test the connection and sure that everything works well and secondly we are going to be saving our Illumina information or data to firebase database so guys we're not wasting much time let's jump right into it but before I forget if you're yet to watch the previous videos my advice is that you watch them then you come back and join us in this particular video the reason is so that you can be in sync with everything that we've been doing and if you are yet to subscribe to the channel please consider hitting the subscribe button and turn on the notification Bell so that you always get notified whenever I made this kind of video now let's get right into it so add in firebase database - our project is quite straightforward the first thing we need to do will be to go to firebase console and create a new project so what I'm gonna do is to pull up my Google Chrome and go to console of firebase.com so log on here so this is the firebase console we're gonna go ahead and add a new project now I'm gonna call this xamarin firebase because that's the name of our project so I'm gonna go ahead and deselect this and how click on continue so we're gonna go ahead and create our project boom so we're don't I'm gonna go ahead and click on continue so guys our firebase project is ready but before any other thing we need to go ahead and add app as you can see we have iOS Android and the web and unity so I'm gonna go ahead and click on Android so it's asking us for our Android package name so to ensure that we put the right thing I'm gonna go back to visual studio now I need to go to manifest our Android manifest ok so this is our package name but I want to change this I don't want it to be summer in firebase but summer in firebase so the easiest way to do that is to go to project and go to summer in firebase properties ok so here I'm gonna click on Android manifest I'm going to change the package name to something nice so I'm gonna have Commodore you Phoenix don't summer in firebase so now that we have this I'm gonna go ahead and copy it after copying it in short to save this information by using ctrl s so this is save this information so I'll close this out now I need to return to firebase console I'm gonna paste this here so this is all we need to do so I'm gonna go ahead and click on register app boom so the next thing we need to do a bit so download the Google services the JSON file because this is actually very useful so we're gonna need to add it to a project later on today everything we won't dress very well so now that we have this I'm gonna go ahead and close this out so added an app to our project now the next thing we need to do will be to add a database so to do that I'm gonna go ahead and click on database so there are two options here we can actually use cloud file install which is a very new one I'm gonna actually be making a video tutorials on how to use this eventually but for now our focus is on real time database so I'm gonna go here and click on create database I'm gonna select start in test mode and I'm gonna hit enable boom our database is ready I'm gonna go ahead and add something so as you can see guys we've added our database so the next thing we need to do would be to set up our app in such a way that it can not connecting to this database okay now I'm gonna go back to visual studio the first thing we need to do will be to install firebase SDKs okay so I'm gonna right click here and go to manage no get packages so I'm gonna browse for za Marine don't firebase so these are such results I'm going to scroll down to where databases okay so this is summary and firebase database this is the one we're interested in so I'm gonna go ahead and click on install so you can see that it's going to install a long side of it with a lot of order dependencies so I'm going to click on OK and I set the licenses boom and we've successfully installed summer in firebase I'm gonna close this out so now that we have that the next thing we need to do would be to add the Google services JSON file that we downloaded earlier on we need to add it to our project so I'm going to go ahead and click here on solution Explorer and on our project side so I'm gonna right click and go to our existing item so in downloads we have Google services JSON I'm gonna go ahead and hide it off so we're gonna go to properties the view doctrine we need to change it to Google service JSON so then I sometimes you might not see the option to set this as Google service JSON what you do here is to close your project before then I have to save all now I'm gonna go ahead and close the project close the solution rather and I need to reopen it again you need to go back to our Google services JSON and go to properties so when you drop down you can screw the list you can now see Google services Jason so select this so that's all we need to do there so guys the next thing is to initialize firebase indeed in alien fashions of hobbies sometimes you might experience you know some issues you initialize the firebase and is no well initialized so I came up with a method of actually smoothly initializing your firebase in such a way that it cannot feel but guys like ILS said I have a knack for keeping things organized so I'm gonna need to create a new folder I'm going to call it helpers now in our helpers for that I'm gonna add a new class so this class I'm going to call it up data' helper so instead of an app design helper I first of all need to make it public and I'm going to make it a static class okay so why I want to make it a static classes because I want it to be accessible you know to how the entire application so wherever you are within the app you can have access to every method that we have in this particular class so we're gonna create a method that will return an instance of our firebase database for us so to do that I'm gonna say public static firebase database okay so I'm gonna call this method get database now we need to resolve this by bringing instances of firebase database ok so have that result now I'm gonna go ahead and say bah up is equal to firebase app so we need to resolve this as well firebase app don't initialize up so I'm gonna pass in application dot contest so next would be to define our firebase database I'm gonna call it database now I'm gonna perform a check to ensure that how if I these were well was correctly initialized so I'm gonna say if app is a quatrain own that is if this initialized app statement field to initialize firebase app so the next thing I'm going to do be to force it to initialize firebase okay so - Ava options this would be equal to new firebase options the Builder so I'm going to hit set application ID so the application ID we can get this from our Google services or JSON so I'm gonna go ahead and open this file Google services or JSON so this is our application ID so I'm gonna go ahead and copy it I'm going to paste it here so needs to be to set our API key we can also get that in our Google services dot JSON file okay so I'm going to copy this so in a paste in here as well so it is our API key now the next thing would be to say set database URL you need to go back to a Google services JSON so this is a database URL I'm going to copy in as well and paste it here now the next thing will be our storage pocket which you can get from our services digestion as well so this is the storage pocket BAM I'm gonna say dot build now I'm going to say app will be equal to firebase app don't initialize app application no contest bracket options so this will go ahead and force our database to initialize with these options that we created now I'm going to say database would be equal to firebase database don't get instance from our app now finally I'm gonna return our database I'm gonna say return database boom I'm gonna go ahead and say else database will be equal to firebase database don't get instance from our app boom now our firebase is completely set up so the next thing we need to do will be to go to our dialog fragment and save the user input to firebase database so I'm gonna go to the dialog fragment so here I need to add a click event handler for submit button so I'm gonna say show me bought in don't click close equal to + tab so this is the submit button click event handler so what I want to do will be to capture the information from who name tells Department has set test and start - spinner and send it to firebase database so to do that I'm gonna come here and say string for name remember guys that this is a test impute layout ok so I'm gonna say don't edit test the test so this will give us the value for a full name so you don't have to do the same thing for the department so I'm gonna say string department should be equal to Department and all so I have to do the same thing for the set so the last piece of data that we need is the status that was selected you know by the user now to be able to get that we need to add an item selected event handler for the status spinner so I'm gonna go to this method the reset up start to spinner I'm gonna say start to spin an item selected okay I'm gonna press tab so this will be the item selected event handler so the lesson I need to do be to declare a new global variable which is taking the value that was selected from start to spinner so I'm gonna come here and say string starters so here I'm gonna say status will be equal to status list and eat opposition so what is actually happening here is that the item selected event handler returns the position for us so we use the position as an index in the status list to retrieve the appropriate status okay so to ensure that we don't make any mistake we're gonna add a check here we're gonna say if either position is not equal to minus 1 so this check is very necessary so that we don't run into errors later on so now that we have the stats with the neste we need to do be to save this information to firebase database so I'm gonna go back to our submit button click event handler so to be able to save data to firebase database we need to make use of hash maps so I'm gonna say hash map I need to resolve this reference so I'm gonna call this Illumina info should be equal to new hash map so the next thing to do will be to add information to this hash map so I'm innocent Illumina info the put so I'm going to put the full name first and I'm going to pass it our full name variable now the nest and the v19 photo put in a passed our department so hash map is more like a key value object so as you can see the Foo name is the key and the value is Funi which is a string variable so finally we're gonna put the status status so the next thing to do would be to pop up a dialog now verified I really want to add this information to a firebase database so I'm gonna say an Android the Buddha I'm gonna call did save data a lot so this will be equal to new and I'm gonna pass my activity to it because as the contest we are Harriton from okay so this is actually very long so I can do here is to use an alias to reduce the length of the code at least for the namespaces and to do that I'm can copy this and go to the top of our code we can say using support v7 which will be equal to this I'm gonna copy support v7 so instead of having all of this I can clean this up and you support v7 so guys is how to make use of alias you might actually come in handy sometimes so I just quickly went ahead I'll show you guys how to make use of that now I'm gonna go ahead and say save data a lot dot site title so this would be this title of our dialogue which will be saved Illumina information the next would be the message the message you read are you sure just to verify that yeah you really want to save this information now finally I'm gonna say save data a lot the set positive button so this is going to be the bottom we will have in our you know a light dialogue so I'm gonna set a button so all we did here was to make use of a lambda expression so it's very short and straight to the point and this is the point where we save our data to firebase database so if we want to retrieve this information we have to first of all have a reference of this part and also to save the information on firebase database you will need a part two where the information will be saved so I'm gonna go back to add to our visual studio I'm going to say that's a base reference so reference is more like a part to where the information will be saved in acordes new Illumina rev this will be helpful too so here we need an instance of our database I'm gonna say app data helper but guys if you really don't like this method you can just go ahead and copy the code and put it somewhere here and call it only on create view method it was stupid same effect but this is more like a way of keeping your code pretty organized and clean so I'm gonna call get database don't get reference so a reference would be Illumina and I'm gonna add the push so this push with generate a unique ID for the information will want to save to how firebase database so finally I'm gonna say new Illumina Rev dot set value and I'm gonna pass in our hash map Illumina info don't and finally I'm gonna say this dot this means I'm gonna dismiss this dialog so this is when the user clicked on continue to go ahead and say this information to firebase database but we are asked the user dean to continue maybe you want to cancel you don't want to save anymore so the next thing we need to do would be to add a negative button so I'm going to say save data a lot dot set negative button so the title of the negative button will be canceled so we're going to make use of lambda expression again so the first things we do will be to dispose this dialog I'm gonna say save data a lot don't dispose so this is all we need to do now to verify that everything works we're gonna need to run an app and test it out so let's go ahead and test our app okay so app is fully running so we're gonna go ahead and click on odd okay so let's go ahead and add the full name so this is my full name say economics say my set is 2009 my status is graduated yes I'm graduated yeah we're gonna pull up firebase database and also our app I'm gonna click on submit so have an error here we need to fix this so he said that department test is a quarter note so we're gonna go head back to our XML the XML for our dialog fragment so we're gonna look through our code okay so it is really problem is coming from so I'm gonna save this I changed it to lowercase when I saved it so this will fix the error now let's go ahead and build an app so why this didn't air out from beginning was because I have another resource that is named Department test but it's not in this video it is in a luminaire role and what we are inflating here is new Illumina and not a luminary role so this wouldn't error outs but to always give us a runtime issue which is what we got okay so before we go ahead and run a have less kind of cross-check our code so finally we need net to say save data a lot dot show so we forgot to add this earlier on so we are ready to rock and roll now guys let's go ahead and run the app okay so our app is fully deployed I'm gonna go ahead and click on add new Illumina so I want to see everything happen so I'm gonna put this up when a firebase database now I'm gonna go ahead and impute my own information so guys feel free to put any information you like so Department we're gonna use economics and set will be twenty nine when it status will be graduated of course I graduated yeah I'm gonna go ahead and click on submit so this is the Allah dialogue that we created earlier on so it's asking what our you shown yes yeah sure boom so guys our data has been added to firebase database so this is the information we provided Department full name set and graduated so guys this is exactly what we want to achieve in this class so stay tuned in the next class when we get into other stars so if you will like this video and you know yet subscribe to the channel please consider clicking the subscribe button and turn on the burner to vacation button so now you can always get notified whenever I made this kind of video but for now
Info
Channel: Ufinix
Views: 17,842
Rating: undefined out of 5
Keywords: android tutorial for beginners, android studio tutorial, learn android programming, android programming, android development, android studio tutorial for beginners, android course, android training, android app development course, Firebase, Xamarin, Android, Ridesharing, firebase, c#, programming, apps, mobile, hashmap, ufinix, xamarin ui, save data to firebase, firebase tutorials, xamarin android, xamarin c# tutorials, xamarin app
Id: W6mTAUWzjV8
Channel Id: undefined
Length: 20min 51sec (1251 seconds)
Published: Wed Apr 17 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.