Android Programming

Android Firebase Tutorial : Introduction


##What Is It ?

Firebase Realtime database is a database backend as a service Cloud hosted solution that gives us the platform to build rich apps.Normally we are used to making HTTP requests to read or write data against our servers.But not in Firebase.It uses synchronization technology that allows it to be realtime,but still performant.

Main points ?

  • Its realtime : Therefore synchronizes data across all devices be it Mobile devices,PCs etc.Whenever there is a data change,events are fired and all connected devices get the updates.

  • Platfrom Independent – Being cloud hosted,any platform that can access internet can take advantage of its features.Be it from a PC,mobile device or web browser,or other servers.

  • Easy Access Control - Security-wise,there is Firebase Realtime database Security Rules.This is expressioned based rules that get called whenever data is to be persisted or read from our database.This ensures that clearly,you can control your data access using simple expressions,that of course get executed on the server side.

  • It’s a NoSQL solution and is heavily optimized for performance.

  • Has Offline capability : Firebase caches data on disk.These data can be accessed even when offline.Normally we are used to write so much code not only to make network operations,but also to oversee good user design guidelines that allows performant apps.The classic way is using threading classes like AsyncTask or Serives like IntentService to poll data so that our User Interface remains responsive.Because firebase persists data on the disk automatically,we don’t have to use the likes of IntentService to poll updates.

  • Its User Friendly.

Here is the new official firebase site.

Firebase Features

Some of the firebase features include :

##(a). Analytics Solution

Gives you insights about your users,their behaviours as well as ad performance

  • Analytics .

(b). Developments Solution

Helps you build better applications.

  • Authentication - provide seamless user authentication within your apps.
  • Cloud Messaging - messaging across applications.
  • Realtime Database - realtime data storage and synchronization.
  • Hosting - host web content like html,css,javascript etc
  • Data Storage - store files like images,video and audio.
  • Remote Configurations - save configuration files on cloud to enable changing them on the fly.
  • Test Lab - app testing.
  • Crash Reporting - track your crash reports.

(c). User Engagement

Helps in user engagement and acquisition.

  • App Indexing - your app available in search results.
  • Notifications - notify users.
  • Adwords - google ads for your app.
  • Dynamic Links - links users to right sections in your application.
  • Invites - sharing from your application.

    (d). Monetization Helps in monetizing your app.

  • Admob - monetize your app.

How Firebase Realtime Database Works

Firebase is realtime.Yes realtime.This means it syncs data across all connected clients or devices,irrespective of the devices themselves.Mmmh!.Be it from a web browser,mobile device,personal computer etc.

During this time the devices remain responsive because of how firebase works.Normally whenever we are doing network operations,be it polling updates from a remote serverWe do so classically by making HTTP requests,either to read or write resources.This normally requires us to do so in background threads or services,making the process tricky and with so much boilerplate.

With firebase, these gets done automatically for us. But even better, it does persist data to disk. So no need to manually write caching and data polling algorithms to maintain fresh data, while keeping our user interface responsive. This is big for real. In fact, even while offline, user can keep adding data.

These gets persisted in the disk. The app remains 100% responsive. Because Realtime events continue being raised. The network comes back. Device connects. The Firebase realtime database jumps to action. It syncs the local data with remote data. Any changes are resolved amicably.

But hey, what about security.Mmh! Security. Well Firebase comes with Firebase Realtime Database Security rules. This is a language, an expression based language. It controls your data access. When data can be read or written .It also structures your data.

Complex access levels can be realized with help of Firebase Authentication. Realtime Database API cannot solve everything. Only operations that complete quick are done using this API.


  • Via Gradle.You include the Firebase realtime database SDK .
  • Create a Realtime database reference that points to your remote data store.
  • Save data, listen for changes
  • Enable offline persistence
  • Use rules to implement security


Sure,we can have talked about Firebase Realtime Database and its cool.But not all data types will be good practice to store in it.For instance binary data like images,videos,pdf files,audio etc won’t be good saving in Firebase Realtime Database.

Instead Firebase or Google if you like,provides a more suited option in Firebase Storage. Code files like Html, CSS and javascript files can be hosted with Firebase Hosting.Also assets like fonts,icons,graphics etc. Infact,there is alson Firebase Remote Config can store app configurations in key value pairs.This can be used by developers to change UI appearance without need for an update.

Creating A new Firebase App

All the above features are independent.To create an app taking advantage of any of them,first you need to use your Google account.You sign up then move to Google Console here.


Firebase Official Guides.

Firebase Official Site.

Firebase Official reference