access_time95 mins remaining

Firebase

access_time95 mins remaining

1. Introduction

Most applications are connected to a backend and utilize external services. Developing your own backend and services can be time consuming, and involves managing the scalability and security of your servers, as well as implementing the features you need, whether that being storing and retrieving user data in real time, authentication through third party identity providers, app analytics, maps and location integration, remote app configuration, etc...

To make app development easier, Google offers a wide array of services. A lot of these features are part of Google Firebase - a service that can act as the backend for your application. Today we are going to see how this service can help us with two fundamental things in app development:

  • Authentication and authorization of your users
  • Storing and retrieving realtime cloud data

What you'll learn

  • How to connect your project with a Firebase backend
  • How to authenticate users of your application with e.g. email/password, Google and Facebook, using Firebase Authentication
  • How to utilize ready made UI and functionality for the sign in/out and registration process using FirebaseUI
  • How to provide realtime cloud storage for your application using Firebase Realtime Database
  • How to restrict read & write access to the database using Firebase Rules

2. Hello Firebase

Create a new project in the Firebase console. Connect that project to a new Android Studio project.

3. Authentication with Firebase

Integrate sign-in functionality using FirebaseUI. When the user is logged in, display a greeting with their username.

4. Signing out

Give an option for the user to sign out.

5. Saving Data with Firebase

Store some data from an EditText on the Firebase Realtime Database.

6. Retrieving Data with Firebase

Retrieve the data from previous exercise and show it in a TextView.

myRef.addChildEventListener(new ChildEventListener() {

   public void onChildAdded(DataSnapshot dataSnapshot, String s) {}

   public void onChildChanged(DataSnapshot dataSnapshot, String s) {}

   public void onChildRemoved(DataSnapshot dataSnapshot) {}

   public void onChildMoved(DataSnapshot dataSnapshot, String s) {}

   public void onCancelled(DatabaseError databaseError) {}

});

7. Bonus: Explore more on your own!

Already done? Expand on the functionality of your application, or try out one of these:

  • Utilize architecture components in conjunction with Firebase
  • Customize the sign in flow with your own layout and more sign in options
  • Populate lists with data from Firebase
  • Explore alternative offerings from Google such as Cloud Storage, Cloud Firestore, ML Kit, Maps, Location API...
  • Create a more elaborate data structure for your app and detail the database rules of the Realtime Database
  • Integrate Google Services into your app project