Welcome folks I am back with another blog post in which I will be implementing this  Firebase Login in Android step by step in the form of Code. The Prerequisites of this tutorial is that you should have a working knowledge of working in Android Studio as we  will be working in Android Studio to implement this project. So first thing Launch Android studio and make a new Project for ex FirebaseSignIn or anything you want.

So the No 1 step is to open Android Studio and create a brand new Project by clicking the start a new project option in the interface.

After opening Android studio and tapping on the Start a new Android Studio Project give a name for your Project and then click next two or three times to build your project

After you click next two or three times gradle the build system of Android will take some time to build your project so wait for some time as it prepares your project. So if all goes well you will get no errors and your build process will be over and you will get this screen.

So after building your project you have to connect your project to Firebase. In order to connect your project to Firebase two approaches are there first is manual and second one is automatic we will follow the automatic and much easier approach here as it’s also the recommended one. We will connect project to Firebase using the Firebase Assistant that is available in Android Studio. Go to Tools and select Firebase and follow the steps listed above

After selecting Firebase under the Tools you will be granted with the Firebase Assistant in which you have to select Email and Password Authentication in order to setup Authentication for your Android project.

After selecting email and password authentication you have to connect your app to Firebase by tapping the button of Connect to Firebase as shown in the figure below.

Just click on the button of Connect to Firebase and then the gradle will connect your project to Firebase in the background and also you will be granted with the screen of selecting the project to connect to Firebase or create a new one . Just click next and  gradle will do the rest for you. If all goes well you will be granted with the following screen and green light will be there.

After this you have to setup Google Sign-In in order to do that you have to go to your Firebase project dashboard. Under Authentication you will find a option called as Sign-in    method select Google Sign-In and simply enable it as shown below.

After that just go to this  link and add these two dependencies into your build.gradle file which is there under gradle scripts just copy this line under dependencies section same to same

implementation ‘com.google.android.gms:play-services-auth:16.0.0’ 

Note that the version has to be same for google play services and Firebase Auth this can be different for you depending on the version of Firebase Auth that is there on your computer for example if version is 16.0.0 then only copy paste this line in my case the version the version was 11.6.0 so I will copy paste

implementation ‘com.google.android.gms:play-services-auth:11.6.0’ 

Add these lines of code into your activity_main.xml file in order to make a simple google Sign-In button into your App

After pasting this code into your project you will get a nice google sign-in button into your android app when you launch it see the screenshot below.

In this code we are just setting some things which include declaring Firebase Auth instance which will eventually kick start the Firebase Authentication for our project and secondly we are just binding a onClick listener to our signin button which is there in the interface so we will create this signin method later which will be invoked when we clicked this button.

Paste this code on the onCreate method of your activity. This code generally means we are setting google sign in options which includes requesting the id token and requesting some standard information from the user which includes email address,profile picture and username of the user.You can also read the documentation to customize this according to your application.

Paste this function code outside the onCreate method. This function is invoked whenever we press the sign-in button in our app. After pressing the button this function will invoke a window which will contain different accounts to select from. The first line is calling a getSignInIntent method on google sign in client object which will return a Intent which we are storing in intent object. Then we are passing this intent object to startActivityforResult method which is a very common method which takes the actual intent object and a  constant which we have declared for this intent in the form of RC_SIGN_IN. I have given this constant a value of 1 you can give any value depending on your choice.  

Paste this function code outside the onCreate method. This function onActivityResult is a standard method which returns the result of the intent that is passed to it when we invoke startforActivityResult method. It takes three arguments first the request code which we pass in the form of RC_SIGN_IN constant and the result code which tells the status of the intent whether it is passed or failed and thirdly the data associated with that particular intent. You can see in the above code we are comparing the request code to our request code if that’s the case then we will perform the operations on GoogleSignIn. We are invoking a method of getSignedInAccountFromIntent and we will pass the intent data to it. If the method runs successfully it will return a task object which then we can use to invoke getResult method which will return GoogleSignInAccount object which we will use as a parameter to the function firebaseAuthWithGoogle which will authenticate the personal data of our account to Firebase. This function we will create in the next step.

Paste this code outside the onCreate method this method firebaseAuthWithGoogle does all the hard work to connect our personal data to the firebase project and then synchronize it when this function executes successfully then we can safely say that we are successfully authenticated with Firebase. As you can see in the code also if all the things goes well then we are simply taking the data which is stored in the FirebaseUser object and then invoking some methods on that object to get username,email address and profile picture of the user and then calling the method updateUI which is responsibe to update the interface. We will create this method in the next step.

Paste this code outside the onCreate method. This function is responsible for updating the interface if we are successfully authenticated with firebase and also fetch the details about the user and display them. You can see in the following code we are not displaying the details of the user in this activity we are moving it to the profile Activity passing a intent object with some data of the user like username,email address and profile picture which we will display in the profile Activity.

Also paste these lines of code in the onStart method of the activity so that we can check if the user is already logged in or not. If the user is already logged in then we can automatically go to the profile Activity and display the details about the user but if the user is not logged in then if condition will evaluate to false then the user will be granted with the login screen.

In order to display the details about the user create a new Activity called ProfileActivity you can call it anything you want and copy paste the below xml code into your activity_profile.xml file.

This is the xml code of the Profile Activity class in this we have used one imageView to display the profile picture of the user and two text views in order to display the username and email address of the user and lastly a button is there to allow users to safely logout from their accounts.

In the Profile Activity copy paste the following code in this code we are just initializing the views that we have declared in xml code i.e. one imageview for profile picture and two textviews for email and username and one logout button we have binded a onclick listener to that button and called a simple logout method on FirebaseAuth object mAuth as simple as that the logout method is very simple as compared to the authentication part. Also we have used a method of intent.getStringExtra which fetches the data that is passed to the activity and after that we have just set the value of username and email address to the respective values.

Copy paste the following line into the build.gradle file this is the dependency of Picasso a famous library for displaying images from url , local file system into imageviews. 

Copy paste this line into the onCreate method of the activity this line just fetches the image url and loads into the appropriate imageView.

Once again copy paste these lines of code into the onStart function but this time we will check if the user is already logged out then we will move the user to the login Activity as you can see in code also if that’s the case we are redirecting the user to MainActivity by the help of Intent but if the user is already logged in then display the details of the user.

Congratulations we are done making the Firebase Google Login in Android from scratch. All the source code of the Application is available below to download. Thanks for reading this post and if you like reading this and wants to read more of this please subscribe the blog below to get all the notications.

A programmer scientist by the mind and a passionate blogger by heart ❤️. Fountainhead of Coding Shiksha Life motto: Live while you can! Teach & inspire while you could & Smile while you have the teeth.

Gautam Sharma

Founder , Coding Shiksha


  1. Alvaro

    You can even replace your chosen MP3 music with your to
    ensure that even if you are regarding the gym, it is possible to still understand interesting
    points from your book or listen towards the docs from perform that you simply should
    examine. Contestants worldwide will record songs independently, or get together into virtual bands of 2 to 4 musicians, and compete
    for $5600 in prizes. Here you’ll be able to shop by theme
    or browse an entirely variety of themes should you be sill unsure about what to base
    the party.

  2. camera wifi

    I do accept as true with all the ideas you have introduced for your post.
    They’re really convincing and will definitely work. Nonetheless, the
    posts are too quick for beginners. Could you please lengthen them a bit from subsequent time?
    Thanks for the post.

  3. camera wifi không dây

    I read this piece of writing completely on the topic of the comparison of hottest and previous technologies, it’s remarkable

  4. True White Whitening System Shark Tank

    I loved as much as you’ll receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get got an nervousness over that you wish be delivering the
    following. unwell unquestionably come more formerly again as exactly
    the same nearly very often inside case you shield this hike. https://truewhitewhiteningsystem.com/

  5. camera wifi

    It is truly a great and useful piece of information. I am satisfied that you just shared this helpful info
    with us. Please keep us up to date like this. Thank you for sharing.

  6. camera ip

    Hello! Would you mind if I share your blog with my twitter group?

    There’s a lot of folks that I think would really
    appreciate your content. Please let me know. Thanks

    • Gautam Sharma

      bro please share it across all your social platforms including twitter too please do it

  7. camera wifi

    Hello, Neat post. There is an issue along with your web
    site in internet explorer, could check this?
    IE nonetheless is the marketplace leader and a large section of people will miss your fantastic writing because of this problem.

  8. camera ip

    Hi there, I enjoy reading through your article.

    I wanted to write a little comment to support you.

  9. https://camerawifihd.info

    We stumbled over here by a different web address and thought I should check things
    out. I like what I see so now i am following you. Look forward to looking into your web page repeatedly.

  10. sex

    Hi there to every one, the contents present at this site are truly awesome for
    people knowledge, well, keep up the nice work fellows.

    • Gautam Sharma

      Thanks very much buddy for appreciate my content

  11. https://gumroad.com/soikeoinfo

    My brother recommended I might like this web site.
    He was once entirely right. This submit actually made my day.
    You cann’t imagine simply how much time I had spent for this information! Thank you!

    • Gautam Sharma

      Thanks buddy

  12. soi keo

    It is perfect time to make some plans for the future and it’s time to be happy.

    I have read this post and if I could I wish to
    suggest you some interesting things or advice.

    Perhaps you could write next articles referring to this article.
    I wish to read more things about it!

  13. sherleneporras27.webgarden.at

    Hello my family member! I wish to say thyat this post is awesome, nice written aand include
    almost all important infos. I’d like to peer molre posts
    like thiis .

    • Gautam Sharma

      Thanks buddy

  14. truck camper backup camera

    Hello there, You’ve done an incredible job. I’ll definitely digg it and personally suggest to my friends.
    I aam confident thjey will be benefited from this website.

    • Gautam Sharma

      Thanks buddy

  15. Millard

    Hello to every one, because I am genuinely eager
    of reading this weblog’s post to be updated regularly.
    It contains good information.

    • Gautam Sharma

      Thanks buddy for your appreciation

  16. www.liveinternet.ru

    Your mode of describing the whole thing in this piece of
    writing is genuknely fastidious, every one be capable of effortlessly understand it, Thanks a lot.

    • Gautam Sharma

      Thanks a lot buddy for your appreciation

  17. http://www.jobref.de/

    I reallly lioke yoir blog.. very nicfe colors & theme. Did you make this website yourself or did you hire someone to do it
    foor you? Pllz reply as I’m looking too crsate my own blogg and would like to find out where u
    got this from. many thanks

    • Gautam Sharma

      I really built from the divi theme it is beautiful you can also use it

  18. Woodrow

    Everything is very open with a very clear explanation of
    the issues. It was definitely informative. Your website is very helpful.
    Thank you for sharing!

  19. InstaBuilder 2.0 WordPress Plugin

    Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog?
    My website is in the exact same area of interest as yours and my
    visitors would really benefit from some of the information you present here.

    Please let me know if this ok with you. Appreciate it!

    • Gautam Sharma

      Please send me the link of your website on to my gmail id ie geekygautam1997@gmail.com then we can negotiate

  20. bedding sets for Queen

    Spot on with this write-up, Itrhly believe that this web
    site needs a lot more attention. I’ll probably
    be bback again to read more, thanks for the information!

  21. led panel light precio

    Superb blog! Do you have any recommendations for aspiring
    writers? I’mplanning to start my own site soon buut I’m a little lost on everything.
    Would you suggest starting with a free platfolrm like WordPress or go for a paid option? There are
    so many choices out there that I’m totzlly overwhelmed ..
    Any recommendations? Thanks!

  22. autumnswader9.hatenadiary.com

    This blog was… how do I say it? Relevant!!Finnally I have found something which
    helped me. Kudos!

  23. 2 x 4 led troffers

    I know thi web site offers quality based content and extra
    material, is there any other website which offers such
    stuff in quality?

  24. thebluescrossroad.com

    Very quickly this web page will be famous amid all
    blog viewers, due to it’s good content

  25. cnc rebar bending machine

    It is not my firrst time to visit this web site,
    i am browsing this wweb site dailly and get fastidious information from here every day.

  26. led 2x4 light fixture

    Very good info. Lucky me I ran across your website by accident (stumbleupon).
    I have book marked it for later!

  27. streetlampsolarnews83.unblog.fr

    When soke one searches for his necessary thing,so he/she wishes too be available that in detail, therefore that thing is maintained over here.

  28. used sachet filling machines for sale

    My family members always saay that I am wasting my time here at
    net, however I know I am getting familiarity all tthe time by
    reading thes nice articles oor reviews.

  29. iPhone touch screen kit solution

    Tanks a llot for sharing this with all folks you really understand
    what you’respeaking about! Bookmarked. Kindly also consjlt with my website =).

    We will have a hyperlink alternage contract
    between us

  30. camera wifi giá rẻ

    Hi there! Would you mind if I share your blog with my twitter
    group? There’s a lot of people that I think would really enjoy your content.

    Please let me know. Thank you

  31. jantzenjantzen25.drupalo.org

    Purely to follow up on the up-date of this subject on your site
    and would want to let you know just how much I appreciated the time you took to create this valuable post.
    Within the post, you actually spoke on how to
    definitely handle this problem with all ease. It would be my personal pleasure to build up some more strategies from
    your site and come as much as offer other
    individuals what I have benefited from you. Many thanks for your
    usual good effort.

  32. LED panel light

    Good bloog yyou have got here.. It’s hard to find excellent writing like yours nowadays.
    I seriously appreciate individuals like you! Take care!!

  33. Chapitre 923 VF

    One Piece 923 en ligne. Coup de froid sur One Piece.

  34. Trista

    Hey fantastic website! Doees running a blog such as this take
    a great deal of work? I’ve absolutely no expertise in computer programming but I was
    hoping to start mmy own blog in the near future. Anyhow, if you have any recommendations or tips for new blog ownwrs please
    share. I understand this is off topic however I simply had to
    ask. Thanks!

  35. 안전놀이터

    Hi! I could have sworn I’ve been to this blog
    before but after going through many of the articles I realized
    it’s new to me. Anyways, I’m definitely pleased I discovered
    it and I’ll be book-marking it and checking back frequently!

  36. led headlight h4 bulb

    Wonderful site you have herre but I was wondering if you knew
    of any commjunity forums that cover the same topocs talked about in this article?
    I’d really like to be a part of community where I can geet advice from other knowledgeable individual
    that share the sqme interest. If you have any recommendations, please let me know.
    Appreciate it!

  37. Elizabeth

    An impressive share! I’ve just forwarded this onto a friend who
    has been conducting a little research on this.
    And he actually bought me breakfast because I found it
    for him… lol. So allow me to reword this…. Thank YOU for the
    meal!! But yeah, thanx for spending some time to discuss this matter here on your internet site.

  38. sgp togel

    I pay a visit daily some websites and sites to read articles or reviews, except this webpage
    provides feature based posts.

  39. free movies

    Hi, just wanted to mention, I enjoyed this post. It was helpful.

    Keep on posting!

  40. cable ties steel

    What’s Taking place i’m new to this, I stumbled upon this I
    have foud It positively useful and it has aided me out loads.
    I hope to contribute & help different customers like its aided me.
    Good job.

  41. http://thietbithungan.vn/tin-tuc/ma-vach-cac-nuoc-tren-the-gioi-484.html

    Undeniably believe that which you stated. Your favorite reason seemed to be on the net the easiest thing to be
    aware of. I say to you, I definitely get annoyed while people think about worries that they plainly don’t
    know about. You managed to hit the nail upon the top and also defined out the whole thing without having side-effects , people
    could take a signal. Will probably be back to get more.

  42. http://checocuc.com/dia-chi-mua-che-thai-nguyen-ngon-o-ha-noi.html

    I’m extremely impressed with your writing skills as well as with the layout on your blog.
    Is this a paid theme or did you customize it yourself?
    Either way keep up the nice quality writing, it’s rare to
    see a great blog like this one these days.

  43. https://www.zzyscasting.com

    I’m more than happy to find this great site. I wanted to thank you for ones time just for this wonderful
    read!! I definitely really liked every part of it
    and i also have you book-marked to see new things on your

  44. led headlight h7

    Excellent blog here! Also your website loads up fast! What hozt arre
    you using? Can I get your affiliate link to your host?
    I wish my site loaded up as quickly as yours lol

  45. website

    Hi I am so thrilled I found your weblog, I really found you
    by accident, while I was browsing on Digg for something else, Anyhow I am here now and would just
    like to say thanks for a fantastic post and a all round interesting blog (I also love the theme/design), I
    don’t have time to look over it all at the
    moment but I have bookmarked it and also added your RSS feeds, so when I have time I will
    be back to read a great deal more, Please do keep
    up the excellent work.

  46. Website

    My spouse and I stumbled over here from a different web page and
    thought I might as well check things out. I like what I see so
    now i am following you. Look forward to looking at your web page again.

  47. door access control systems

    A motivating discussion iis definitely worth comment.
    There’s no doubt that that you ought to publish more about this subject matter, it mibht not be a taboo subject but generally people do not discuss these issues.

    To thee next! Cheers!!


Submit a Comment

Your email address will not be published. Required fields are marked *