Chapters

Hide chapters

Saving Data on Android

First Edition · Android 10 · Kotlin 1.3 · AS 3.5

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Using Firebase

Section 3: 11 chapters
Show chapters Hide chapters

11. Firebase Overview
Written by Dean Djermanović

Creating a successful mobile app isn’t easy. Not only do developers need to focus on writing code and fixing bugs, they often need to manage a variety of tools and build complex infrastructures too. Factor in tight schedules and resource constraints, and you’ve got your work cut out!

Thankfully, though, Google understood the need for a simpler way to create high-quality apps, and in 2014 they acquired Firebase. More recently, Google announced that in October 2019, they will start to sunset their existing Google Analytics for mobile apps and is directing its users to use Firebase instead. With Firebase, developers got all of the existing functionality of Google Analytics, plus a lot more.

Note: The Google Analytics referred to hereafter in this book is a new sub-feature of Firebase and not the legacy platform.

Firebase history

Initially, Firebase was a mobile backend service that let you build mobile apps without having to worry about managing your own backend. However, not too long after its release, developers wanted more, so Firebase expanded its initial feature set to include more features. With these new features, you can develop apps faster, increase your user base, make more money and ensure the delivery of high quality apps. On top of all that, there’s an analytics product that ties it all together.

Note: Most modern mobile apps require a data access layer for things that can’t be done solely on a device, like sharing and processing data from multiple users or storing large files. The remote server, typically known as the backend, is responsible for handling these backend services.

Why Firebase?

Firebase is known for its easy-to-use APIs, great documentation and fantastic developer support. In addition to that, it only takes a few minutes to integrate Firebase with your projects.

Today, apps are rarely developed for a single platform, and most mobile apps are developed for the two biggest: Android and iOS. For that reason, developers often look for cross-platform solutions.

Firebase is a cross-platform service that works on Android, iOS and the web. By using a cross-platform solution, developers are not spending as much time as they would if they needed to use a separate service for each one. Not to mention, there’s no need for businesses to invest additional money for different platforms.

Another bonus to using Firebase is that its products are integrated into one set of tools. There’s a single SDK, a console and one place to go for the documentation and support. Data between different Firebase products is shared where and when needed, which leads to even faster development.

Getting started

Firebase console

The Firebase console is where you set up and manage your apps. From there, you can view all of your projects as well as create new ones.

To get started with Firebase, open your web browser and navigate to console.firebase.google.com.

If you’re not already logged in, do so now, and you’ll see this screen:

To get started, you’ll create a simple social media app that lets you share your thoughts with other app users.

First, you need to add your app to Firebase. Follow the steps:

  1. Click Add project.

  2. For the project name, enter WhatsUp.

  3. Uncheck Use the default settings for sharing Google analytics for Firebase data.

  4. Click Continue.

  1. You’ll see another screen with additional options to customize data sharing. Leave them all unchecked and click Create project.

Once your project is created, click Continue. You’ll see this screen:

That’s it! You’ve successfully created your first Firebase project.

Now, click on the Develop option from the menu on the left and then select Authentication. Authentication screen shows up:

Click on the Sign-in method and among the sign-in providers click on Google. Enable Google sign-in and click save:

This allows your app users to authenticate with their Google account.

Firebase analytics

To build a successful app, you need to clearly understand how your users behave and how they use your app. This is why analytics are so important.

There are many analytics categories that your app can use. This includes, in-app behavior analytics, which measures who your users are and what they are doing; attribution analytics, which you can use to measure the effectiveness of your advertising and other growth campaigns; push notifications analytics, crash reporting analytics and more.

Without Firebase, you may need to use multiple analytics libraries and tools to collect and save your analytics data. This becomes problematic when you need to share analytics data among those tools. Analytics for Firebase, however, is built to provide all of the data mobile app developers need in one place. Analytics integrates across Firebase features and provides you with two key capabilities: unlimited reporting for up to 500 distinct events and audience segmentation. With audience segmentation, you can create a custom audience that you target with new features or notification messages, for example. You can choose your custom audience base using parameters like device data or user properties.

Once you integrate your app with Firebase, analytics comes standard out-of-the-box.

Developing

Firebase offers many products that help you develop your app. Products that you’ll use in this section of the book are Authentication, Realtime Database, Cloud Firestore and Cloud Storage. Let’s take a look at each one.

Authentication

Most apps need a way to identify a user so they can customize their experience and keep user data secure, while making authentication easy for both end users and developers.

Firebase supports many different ways for your users to authenticate. Firebase Auth has built-in functionality for third-party providers such as Facebook, Twitter, Github or Google. If you want to authenticate users via an email address, you can do that, too.

You can present login functionality to the users in two different ways: using your own interface or taking advantage of Firebase’s open source UI, which is also customizable. When the user authenticates, information about that user is returned to the device via a callback. You can then use that information to customize the experience for the specific user.

Firebase also manages user sessions, which means that users will remain logged in after the app restarts.

Realtime Database

Many apps need a way to store and share data from the server. When building your own backend, there are a few things that you need to manage, such as setting up and maintaining the database, real-time data synchronization and offline support. This can be tedious and time-consuming.

Firebase Realtime Database does it all for you, including storing and syncing data in real time. This allows users to access the data from any device.

Data is stored on the cloud, and whenever data is updated, all relevant devices get notified simultaneously within milliseconds.

Realtime Database is also optimized for offline use. It uses a local cache to store changes when the user loses network connection and when it comes back online local data gets automatically synchronized.

Realtime Database also takes care of security. You can use security rules to specify who has access to various pieces of data. Security rules are securely stored on the server.

Cloud Firestore

Cloud Firestore, like Realtime Database, is also used for saving the data to the cloud. It comes with the same feature set as Realtime Database, letting you store data in the cloud and sync data among different devices or share it with other users.

Cloud Firestore comes with client libraries, full offline mode support, a comprehensive set of security rules that help manage access to the data and a data browsing tool. It allows you to structure your data in a way that makes sense to you. It also automatically fetches changes from the server as they happen, or if you prefer, you can fetch them manually.

Cloud Firestore also integrates with other Firebase products like Authentication. You’ll learn the differences between Realtime Database and Cloud Firestore as you progress through this book.

Cloud Storage

When it comes to storing and sharing pictures and similar files, Cloud Storage is crucial. Cloud Storage lets you upload user files to the cloud so they can be shared with others. If you want to share those files with specific users, you can leverage Firebase Authentication for that.

All network transfers are performed through a secure connection. If the connection breaks during network transfer, the transfer is paused and resumed once the network connection comes back online. This makes Cloud Storage ideal for large files or slow and unreliable network connections.

Other products

Firebase also offers other products for developing your app that aren’t covered in this book. These include ML Kit, Cloud Functions and Hosting. You can learn more about them by reading the official Firebase page at https://firebase.google.com/products/.

Improving app quality

Firebase can help you improve the quality of your apps.

Before pushing your app to production, you need to test it. For that, Firebase provides you with Test Lab.

With so many different devices out there, you need to ensure that every feature of your app works as expected regardless of screen size or operating system version. Testing on every device is challenging since most developers don’t have access to all available device. Firebase Test Lab makes it possible to test your app with a variety of physical devices hosted in the cloud.

Bugs are frustrating for users and can cause them to uninstall the app and negatively impact its success. Many things can go wrong in the app and cause it to crash. Firebase Crashlytics collects, analyzes and organizes crash reports. It can also help you prioritize issues so that you can fix the most important ones first.

Your users will use your app in different circumstances — different devices, different networks and different locations. You need to provide the best user experience to all of them. To do that, you need metrics that tell you what’s happening during critical moments of your app’s use.

The only way to get that information is from the users themselves or by using Firebase Performance Monitoring. The Performance Monitoring SDK collects information about your app’s performance, such as the app’s startup time or details about HTTP transactions. You can also use the provided API to instrument your app to measure critical moments that you want to improve.

Growing a business

Firebase has several products that you can use to methodically grow your app, gain more users and help you earn more money.

In-App Messaging helps you engage users who are actively using your app by sending them targeted and contextual messages that nudge them to complete key in-app actions, like beating a game level or buying an item.

Google Analytics for Firebase gives you the power to build up groups of users, or audiences, out of just about anything you can measure in your app. It provides free, unlimited reporting on up to 500 distinct events.

Key points

  • Firebase is Google’s mobile platform that helps you quickly develop high-quality apps and grow your business.
  • Firebase consists of three main pillars: Develop, Improve and Grow.
  • Firebase console is a single place where you need to go to set up and manage your app.

Where to go from here?

There’s a lot more to explore in Firebase. You can find out more about different Firebase products and their key features in the official Firebase documentation.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.