Summary: Methods | Inherited Methods | [Expand All]
public class

# FirebaseDatabase

extends Object

java.lang.Object
↳ | com.google.firebase.database.FirebaseDatabase

## Class Overview

The entry point for accessing a Firebase Database. You can get an instance by calling `getInstance()`. To access a location in the database and read or write data, use `getReference()`.

## Summary

Public Methods
FirebaseApp | getApp() Returns the FirebaseApp instance to which this FirebaseDatabase belongs.
static FirebaseDatabase | getInstance() Gets the instance of FirebaseDatabase for the default FirebaseApp.
static FirebaseDatabase | getInstance(FirebaseApp app) Gets an instance of FirebaseDatabase for a specific FirebaseApp.
DatabaseReference | getReference()
DatabaseReference | getReference(String path) Gets a DatabaseReference for the provided path.
DatabaseReference | getReferenceFromUrl(String url) Gets a DatabaseReference for the provided URL.
static String | getSdkVersion()
void | goOffline() Shuts down our connection to the Firebase Database backend until `goOnline()` is called.
void | goOnline() Resumes our connection to the Firebase Database backend after a previous `goOffline()` call.
void | purgeOutstandingWrites() The Firebase Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity.
void | setLogLevel(Logger.Level logLevel) By default, this is set to `INFO`.
void | setPersistenceEnabled(boolean isEnabled) The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Methods

#### public FirebaseApp getApp ()

Returns the FirebaseApp instance to which this FirebaseDatabase belongs.

##### Returns

- The FirebaseApp instance to which this FirebaseDatabase belongs.

#### public static FirebaseDatabase getInstance ()

Gets the instance of FirebaseDatabase for the default FirebaseApp.

##### Returns

- A FirebaseDatabase instance.

#### public static FirebaseDatabase getInstance (FirebaseApp app)

Gets an instance of FirebaseDatabase for a specific FirebaseApp.

##### Parameters

app | The FirebaseApp to get a FirebaseDatabase for.

##### Returns

- A FirebaseDatabase instance.

#### public DatabaseReference getReference ()

#### public DatabaseReference getReference (String path)

Gets a DatabaseReference for the provided path.

##### Parameters

path | Path to a location in your FirebaseDatabase.

##### Returns

- A DatabaseReference pointing to the specified path.

#### public DatabaseReference getReferenceFromUrl (String url)

Gets a DatabaseReference for the provided URL. The URL must be a URL to a path within this FirebaseDatabase. To create a DatabaseReference to a different database, create a `FirebaseApp` with a `FirebaseOptions` object configured with the appropriate database URL.

##### Parameters

url | A URL to a path within your database.

##### Returns

- A DatabaseReference for the provided URL.

#### public static String getSdkVersion ()

##### Returns

- The semver version for this build of the Firebase Database client

#### public void goOffline ()

Shuts down our connection to the Firebase Database backend until `goOnline()` is called.

#### public void goOnline ()

Resumes our connection to the Firebase Database backend after a previous `goOffline()` call.

#### public void purgeOutstandingWrites ()

The Firebase Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity. In some cases (e.g. offline usage) there may be a large number of writes waiting to be sent. Calling this method will purge all outstanding writes so they are abandoned. All writes will be purged, including transactions and `onDisconnect()` writes. The writes will be rolled back locally, perhaps triggering events for affected event listeners, and the client will not (re-)send them to the Firebase backend.

#### public void setLogLevel (Logger.Level logLevel)

By default, this is set to `INFO`. This includes any internal errors (`ERROR`) and any security debug messages (`INFO`) that the client receives. Set to `DEBUG` to turn on the diagnostic logging, and `NONE` to disable all logging.

##### Parameters

logLevel | The desired minimum log level

#### public void setPersistenceEnabled (boolean isEnabled)

The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored. However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value to `true`, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time). Note that this method must be called before creating your first Database reference and only needs to be called once per application.

##### Parameters

isEnabled | Set to true to enable disk persistence, set to false to disable it.