How Firebase Works in Android (With Examples)

Advertisements

If you already know what Firebase is? Let’s talk about how Firebase works in Android like a  pizza in the Firebase’s stomach.  😂

Firebase is a backend service for mobile and web applications and provides dozen of useful backend services like:

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 IDEs out there for Android Apps development like Xamarin, Visual Studio, and Eclipse, but we’ll use  “Android Studio.” as recommended by Google.

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’ll not explain here how to install Android Studio; it is pretty straightforward 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. You need to choose 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, you need to leave all the default settings.

Configuring Android Studio Project Screenshot

Remember, it’ll take a few minutes or more if you are creating your first project.

We are not interested in coding; for now, we’re 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’ll 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’ll 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 selected Firebase Analytics so you 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 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?

Check out 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 the 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, but:

  • 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
  • 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.

Don’t forget to ask questions if you have on your mind. I’ll be delighted to answer your question below.