Java / Android Quickstart Guide

First, you'll need to sign up to get your own Firebase.

Get The Library

You can use the Firebase SDK by downloading a jar or installing via Maven.

Download and Install

You can grab the latest jar by right clicking below and choosing "Save As...":

Download Firebase Java SDK

After downloading the jar, place it on your application's classpath. Typically, this is in your 'libs' folder. Depending on your IDE, you may need to explicitly add the library to your project. For example:

Eclipse

Android Studio

Maven

If you use Maven to build your application, you can add the following dependency to your pom.xml, in the dependencies section:

<dependency>
  <groupId>com.firebase</groupId>
  <artifactId>firebase-client</artifactId>
  <version>[1.0.7,)</version>
</dependency>

Note for Android Developers

The Firebase library requires the INTERNET permission to operate. Your app will not work unless you add this permission! Make sure that the following line appears in your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

Getting Started

Using the Firebase API to synchronize your data is easy:

// Create a reference to a Firebase location
Firebase ref = new Firebase("https://myapp.firebaseIO-demo.com/");

// Write data to Firebase
ref.setValue("Do you have data? You'll love Firebase.");

// Read data and react to changes
ref.addValueEventListener(new ValueEventListener() {

    @Override
    public void onDataChange(DataSnapshot snap) {
        System.out.println(snap.getName() + " -> " + snap.getValue());
    }

    @Override public void onCancelled() { }
});

Notes

  1. By default, on Android, all callbacks are executed on the main thread. On other JVM targets, callbacks are executed on a new, separate thread. You can configure this behavior by providing your own EventTarget to the default Config used by the library.

  2. Firebase references are very lightweight. Furthermore, two references pointing to the same location are completely interchangeable. Create and discard them as needed.

Next Steps

If you haven't already done so, you should try our tutorial. Next, we recommend checking out our example apps or reading on in the docs:


Have a suggestion to improve the documentation on this page? Tell us!