Skip to content

Firebase Storage – A step by step guide to build a Cloud Firestore demo using Firebase Cloud Firestore Database

Become a developer with our complete learning paths
Become a developer with our complete learning paths

In this article you will learn how to build the Cloud Firestore demo for your application using Firebase Cloud Firestore Database. This demo will show you how to create an application that will store the user details in the firebase cloud firestore database. All you need to do is follow the steps below one by one.

Follow all the steps one by one to build the Cloud Firestore Database demo

  1. Create a new project using Android Studio.
  2. Select a project template as Empty Activity. After that, click Next.
  3. Name the app as “CloudFirestoreDemo” and also update the package name as “com.cloudfirestoredemo.” If you want, you can name the app or package differently. You can also edit the project save location.
  4. Select the language as Kotlin.
  5. Click on Finish. After clicking on the finish button, the project will be created and the necessary files will be built.
  6. Once you are done with the project setup, we can run the application. 
  7. You can see our application build and installed on the device. 
  8. Now, go to the CloudFirestoreDemo app and select the “Gradle” from the right side, as shown in the image.
  9. The next step is to expand the CloudFirestoreDemo. You will see two other options: task and app.
  10. Select app -> Tasks -> android.
  11. Double click on the signingReport.
  12. You will see the SHA1 Key of the application, as shown in the image below.
  13. We will use the SHA1 Key in the Firebase Console while creating the project.
  14. Now go to the Firebase Console.
  15. Login to your Gmail account if you are asked to.
  16. As shown in the image of Firebase Console, you will see the below screen once you are logged in. Once again, use your gmail account for that. 
  17. Now, click on the Add Project.
  18. Enter your project name as “CloudFirestoreDemo.
  19. Click on Continue.
  20. There is an option for Google Analytics for your Firebase project. We will disable it for now. I will show you what is it and how to use it later, not in this demo.
  21. Click on the Create Project.
  22. It will take a couple of seconds, and the project will be created in the Firebase Console.
  23. Once it is done, click on the Continue button.
  24. You will see the screen below once your project is created successfully.
  25. To add your app, select the Android icon shown in the image above.
  26. Once you select the Android icon, you will see the below screen. You need to fill up the details.
  27. In the above image, as you have seen, you need to add the application package name. You can find the package name in the app level Gradle file. Add the app name. You should also add the SHA1 key that we have generated above in the application. The SHA1 key is optional, but we recommended to add it for security reasons.
  28. After adding all the details, click on the Register app.
  29. Once the app is registered, you will have an option to “Download google-services.json.” Download it and add it to the location as shown in the image.
  30. After adding it, click on Next.
  31. Add the Firebase SDK in the respective Gradle files, as shown in the instructions.
  32. Now click on the Next.
  33. After performing all the steps, we are done with the setup.
  34. Now we will start the implementation of the Cloud Firestore Database in our application.
  35. To know more about the cloud firestore database, please have a look here.
  36. Learn the implementation steps from the official document of Firebase from here.
  37. The final version for the app-level Gradle file PASTE THE LINK HERE.
  38. After you have added the Gradle file’s dependency, we need to follow the below steps before moving further.
  39. Go to the Firebase Console dashboard and select the Cloud Firestore from the Develop section on the left side.
  40. Click on the Create database.
  41. After that, click on Next.
  42. Now select the Cloud Firestore location and click on Enable.
  43. Once the database is created, you will see the below screen.
  44. Now all you need to do is to add the code from the documentation as per your requirement.
  45. We have created a demo where we will store the user name and email id, and once it is stored in the database, we will get and display it in the list using RecyclerView.
  46. You can download the complete source code of the demo and follow the application’s TODO steps.
  47. Design the activity_main.xml file and item layout for RecyclerView as item_user.xml.
  48. Create a data model class name as User.
  49. Create an adapter class name as UserListAdapter.
  50. Now, add the code to store the user details on the cloud firestore database and get the users list from it in the MainActivity.
  51. Now run the application and test it.
  52. If you face the below error in your code, then implement the Multidex in the app.
  53. After the demo is completed and you can make an entry in the database, you will see the entry as below.
  54. Now we are done with the demo.

You can get the complete source code of the demo.

Summary

In this article, you have learned to store the user details in cloud firestore database in your application.

Lost in coding? Discover our Learning Paths!
Lost in coding? Discover our Learning Paths!
Enter your email and we will send you the PDF guide:
Enter your email and we will send you the PDF guide