How Firebase Works in Android? Understand in the Easiest Way

Do you know what Firebase is? Let’s talk about how Firebase works in Android.

If you don’t know what is Firebase?

It is a backend service for mobile and web applications and can provide dozen of useful backend services like

  • Hosting
  • Authentication
  • Push notification
  • Executing A/B testing

and much more to Android, iOS, Unity and Web applications too.

But here we will cover how Firebase in Android? How we can add it to Android, what kinda problems it can solve for us.

Understand How Firebase Works By Creating an Environment for Firebase

Thus, in order to use Firebase in our Android project, we need an Integrated Development Environment, aka IDE.

There are many IDE out there for Android Apps development like Xamarin, Visual Studio, Eclipse, etc. but we will talk about the one developed and recommended by Google, named “Android Studio.”

First, you need to install Android Studio; it is available for both Mac and Windows.

You can download it from its official website.

Install Google Studio
Install Google Studio. I cannot explain here how to install Android Studio; it is pretty easy and mentioned on their website too. Please check out the system requirements before you download this 700 MB file.

Once downloaded and installed, you need to create an Android Project, which involves the following steps

  • Choosing a project – you can select any activity, and its code will be available when the project created. I am selecting the Empty Activity

Choosing Project Android Studio Screenshot

  • Configure your project – provide your app name, package name (must be unique), save location and language and hit Finish button. For this demonstration purpose, I am leaving all the defaults.

Configuring Android Studio Project Screenshot

It will take a few minutes or more if you are creating your first project and then becomes ready for you to code. We are not interested in coding; for now, we are here for knowing how the firebase works in Android, right? So we will jump straight into that.

Firebase Integration via Android Studio

Firebase and Android Studio (also Android OS) are Google’s products; they are made for each other to work as a family.

There are two ways to integrate Firebase in Android Studio.

  1. The Plugin Way (easiest one)
  2. The Manual Way (full of hassles)

Read here the manual way to integrate Firebase SDK if you like complex things.

But today, we’ll discuss the easiest way to understand how Firebase works with the help of a plugin provided by Android Studio.

Firstly,

  • Open your Android Studio Project
  • Head toward Tools from the Menu and select Firebase

Selecting Firebase Plugin in Android Studio Screenshot

  • You will see a pane that will open on the right side, consisting of all the services offered by Firebase.

Showing Firebase Products in Android Studio Screenshot

  • Select an option that you need, but I’m interested in Firebase Analytics, so I’ll click and hit the option “Log an Analytics Event.

Selecting Firebase Analytics Android Studio Screenshot

  • Now the first thing that you need regardless of which product you want to use is connecting your project to Firebase. And to that, you must be logged in to Android Studio using your Gmail account. Otherwise, it will redirect to a browser asking to log in.
  • Once logged in, it will ask you to select a Firebase project you want to connect with or create a new one. You can choose whatever you prefer after that hit the “Connect to Firebase” button at the bottom.

Connecting Android Studio Project to Firebase Screenshot

  • It will take some time to implement libraries to build.gradle file, downloading the JSON file from Firebase and then syncing the project.
  • Once completed, your project will be connected to Firebase. And now you can implement any Firebase product you always wanted.

Implementing Firebase Analytics in Android Studio

  • The instruction for all products is given right in that pane as I was interested in Firebase Analytics so I can see a button saying “Add Analytics to your app.” The same is the case with the rest of the products. When you hit that particular button, Android Studio will add that particular product library to build.gradle file and sync the project. Hence that library functions available for you in Android Studio. In my case, it will add Firebase Analytics library hence making me able to log custom analytics events right into Firebase Console.

So, as you can see, it is very easy to implement Firebase in Android using the provided you use the Firebase plugin in Android Studio.

If you are still confused about the firebase products and want to know which one is best for your app?

Checkout my complete overview of firebase products.

How Can Firebase Help in Android Development?

Firebase is the place where you should come, either you are developing a static app to show users the menu of your client restaurant or if you are building a whole new social media app.

Firebase can definitely help you out because even a menu-showing app, you can not hardcode the menu items and prices.

Because you do not want to open the Android studio project, change the price, sign an APK, roll-out to product and wait for the users to update the app.

That is not an option.

So you have to use a Firebase product called Firebase remote config, where you can save the menu items and their prices in key-value pairs. And update them on the go.

Firebase is not just limited to remote config.

  • You can use Firebase Authentication to authenticate the users for your social media apps
  • You can use Firebase Database to store not just the users’ data like chat messages, but you can also write the security rules regarding the database. And top of that there are two database types available by Firebase
    • Firebase Realtime Database: where data is stored in JSON and synchronized in realtime to every connected client in the form of DataSnapshots
    • Firebase Cloud Firestore: where data is saved in the form of documents and collections, providing even more efficiency.
  • You can use Firebase Cloud Messaging to automate the task like sending a notification at a particular event
  • Last but not least, Cloud Storage can help you to save the users generated content like their profile pic, multimedia messages, etc.

And a lot more.