Login and Registration demo with Firebase database

Part 1- Registration (Saving data)

1.) Create a new Android Project “Firebase Demo“. Create an activity for registering the users and name it as RegisterActivity. Name the layout as “activity_register”. Now, Add the Firebase database in your android project. Go to File -> Project Structure -> Cloud. Click on the check box to add the firebase database. You’ll see the following dependency added into your app level gradle file. Don’t forget to add INTERNET permission in your android manifest file.

<uses-permission android:name="android.permission.INTERNET" />


compile 'com.firebase:firebase-client-android:2.3.1'

Also, add the following packagingOptions in your app level gradle file.

packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'



2.) Go to the Firebase console and create a new project “Firebase Demo” for using Firebase database “Backend as a service“. Copy the Firebase URL. For me, its https://fir-demo-d7354.firebaseio.com/. This URL will be used to connect to the Firebase database from your app. Then, click on ADD APP in the overview page.


3.) Enter the package name of your app from AndroidManifest.xml and the debug SHA1 key. Click on ADD APP. Download the google-services.json file and place it inside your /app directory. At last, add the dependencies in your gradle files.


Project-level gradle file(excerpt)


App level gradle file(excerpt)



4.) Change the permission as below for the Firebase database. We’re setting it to be accessed from anywhere as by default Firebase allow only authenticated user to interact with the database. (Don’t do this in production).


5.) Create a Config class and store the Firebase URL.

6.) Now, design the register page for your users to sign up using the app. For simplicity, we’ll keep only four fields Name, Email, Contact Number and Password.

7.) Create a POJO class for the User and name it as “User.java”. This class is used for saving the user objects  in Firebase database.

8.) Now, add the following code in your RegisterActivity.java.

9.) Run the app. Enter the details of a user and click Register. You’ll all the details saved in the Firebase database.



Part 2 – Login(Retrieving data) 

1.) Add a new static variable in your Config.java for getting a reference of “Users” node.

2.)  Design the layout “activity_login” for getting the Name and password from the user as inputs.

3.) Add the below code in your LoginActivity.

4.) Make the LoginActivity as your Launcher Activity in AndroidManifest.xml and Run the app. On entering the correct Name and password. You’ll see a Toast saying “USER AUTHENTICATED”.



 => DOWNLOAD THE COMPLETE PROJECT: https://github.com/cvivek07/Firebase_Demo

Comment below if you are facing any issues. Thank you 🙂

admin Author

Leave a Reply

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