Firebase Android Tutorial - Part 2 - User Login

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys welcome to firebase tutorial series in the last video we'll learn how we can make user registration to our firebase console and in this video we'll see how we can make user login in our app so when the user is registered he can log into our app so that is what we'll be learning today so the first thing we need to do is create a interface for login so we'll create a new activity so this is your package Android tape on it put the new activity and select empty activity now give this activity a name and giving like login again activity - so this is the login activity and this is the layout file now we need to create to enter email and password and we need to also create a button so the layout is exactly the same way created in the main activity so to make it quick I'll copy this so copy this ctrl C and paste it here ctrl V sorry it does a Mac I'm using a Mac now and I'm calling the command key to control so anyways let's change the IDs and it doesn't matter but it should make some sense so this is the signup and our text would be not an account sign up here so that when user will tap this text view he can navigate to the registration activity again and we can also change the ID for signing so ID should be sign also add large text here you can call that user rocket seems even add to the registration screen so that we can differentiate let's call that user registration now let's come to this login activity first we'll declare the objects the same with the last tutorial so pirate button sign and I get text the text email turn back into text text password and the last one is our text you type a text to you textview sign up now we will initialize the view object using find you by ID so the text email it was 200 texts finally by ID without the 16 name say for password and what kind of text this is a question Sonya so we need to cost you to go button this is text to you and this one we text we knock and this will be a good text password so we have initialized our views object and now let's attach the listener to what I'm signing and text to sign so but I'm signing dog shut on total still after this text to sign up but also comes with listener this now this is giving error because we haven't implemented the interface implemented on cue line interface now we also need to over write down with my third so okay so the method is overridden now now when you check out if you equal to equal to bottom signing so we'll call them a car let's say use above and if u is equal to equal to text we sing so we'll start the activity in intend current activity context and if the sign of this clicked will start the user HSN activity so that activity is main activity dot class and we also need to close this activity so we'll call the third finish so now let's create user login method so yeah I have a permit wide user logon so first let's get the email and password from the Attic text so create a string email first word read text email don't get distracted same for the password press command D and copy it to could be possible now you can check if the imminent passwords are empty we can do this by copying this code quickly progress dialog answer actually we are doing exactly the same with it in the last tutorial copy this code C and paste it here so we also need to create a progress dialog so that when the user is getting log then we can display a progress time so create private time we slice it here - you know this now we need our firebase object so again inside the class let's scale it by a private fire best off now we need to initialize this object by basalt equals to 5 s all dotnet and steps now with this object we can call the method sign in with email and password so we'll do it here this r dot sign with a sign in with email and password and this method will again take two string arguments the first one will be email and the next one is that password now we can also track the completion of the execution of this record so for this we will again - the same display which is add on complete list and this method takes first argument as that duty context so they can pass this and the list so we have the listener and this method will be called when the sign-in will complete so inside this method first we'll distance the progress dialog and then we can check the completion is successful or not that is task object so write f task is successful we can start start down profile activity we also need to track if the user is already logged in or not so inside on create we'll write a fireplace or torque at current user and if it is not null that means user has already logged in so you can directly start profile activity now we don't have a profile activity right now so first let's create the profile activity again go to your package right click new activity and objective give it a name I am given profile so this is our profile activity know again we'll create a linear layout here so practice linear layout move it to the center now inside this will create a text you so much text texts eyd let's change it to text you user meaning and when the user is logged in he obviously needs to log out so we'll also create a button and let's put that text log okay so you button to log out and the ID about this looks good so we'll start this activity when the user is logged in so come to login activity and start that to game start start activity new intent and as you can see right now we are inside test on capitalist and so we cannot pass this to pass the current activity context so you can use get application context or login activity dot this so you can use anything so right get application context and the profile across so profile activity dot cross before starting the another activity you should finish the current activity so this method will close the current activity and the same thing will do on here if the user is already logged in will do the same so copy this come on C and paste it here so login activity is ready oops should be a great text password you pitted from inactivity and it is correct anyways let's continue so login activities ready and inside me in activity will start activity when the user will tap the login button so he should be navigated to the login activity so you intend this and it will not cross and again in the registration screen we can check if the user is already locked in we can directly navigate him to the profile activity so err or just copy the code we have written on connected computers and paste it now after the successful registration we can again start the profile activity so we don't need this if this time so remove this so we are finished in the current activity and starting the profile activity after successful registration inside profile activity again we need to declare the firebase object so like right by a base auth 5ms off and tag stream and turn about now cleans like the views text email equals 2x - 5 V by ID and OD oops the button follow - lets love implement leisure class sorry interface let's check with the firebase Auto V event in slightest object so like fire this art equals to five assault on that instance if firebase or dog cat current user is equal to equal to null that means user is not octane and here we will start start activity new intent to login active letting so this and will not cross and will also finish this activity so all things here now if the user has logged in so the code will not come inside this F so we can directly create a firebase user object here goes to firebase alternative and we can set text you lots a text will come and email the code is ready yes that's tested so on as an entire active sum up sum total of this is text you signal and o to see you so the capital one now let's run again oops we have I'm already logged in so click on logout this is not working let's check the code inside for file activity we have and you don't call the logoff so if you equal to equal to button work out we will call the lockout sign out method from fire this object so write this or tort sign out and then we'll finish the current activity and start the login activity this turn it again so click on logout I'm knockout now this is the user login window let's create on your own so like that we put my of their C male or Damini 3 4 5 6 click on sign so we have successfully signed up and this is the email which we registered and let's click on logout let's just log in on email was a su and they're touching me calm and password was one two three four five six click on sign up should be sign em we have written tuple s so now this is correct what do you find so I'm wrapping up the tutorial here and in the next part we will do some more things like password desert and interrogating analytics and many more firebase features so this is it for now and please do like and subscribe my video if you liked it and see you next time
Info
Channel: Simplified Coding
Views: 174,573
Rating: undefined out of 5
Keywords: firebase, firebase android tutorial, firebase login in android, firebase authentication tutorial, android user registration and login using firebase
Id: tJVBXCNtUuk
Channel Id: undefined
Length: 20min 9sec (1209 seconds)
Published: Sun Jul 31 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.