FirebaseDatabase

class FirebaseDatabase


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 functions

java-static FirebaseDatabase

Gets the default FirebaseDatabase instance.

java-static FirebaseDatabase

Gets an instance of FirebaseDatabase for a specific FirebaseApp.

java-static FirebaseDatabase

Gets a FirebaseDatabase instance for the specified URL.

synchronized java-static FirebaseDatabase

Gets a FirebaseDatabase instance for the specified URL, using the specified FirebaseApp.

DatabaseReference

Gets a DatabaseReference for the database root node.

DatabaseReference

Gets a DatabaseReference for the provided path.

DatabaseReference

Gets a DatabaseReference for the provided URL.

java-static String
Unit

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

Unit

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

Unit

The Firebase Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity.

synchronized Unit

By default, this is set to INFO.

synchronized Unit

By default Firebase Database will use up to 10MB of disk space to cache data.

synchronized Unit

The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running.

Unit
useEmulator(host: String, port: Int)

Modifies this FirebaseDatabase instance to communicate with the Realtime Database emulator.

Public properties

FirebaseApp!

Public functions

getInstance

java-static fun getInstance(): FirebaseDatabase

Gets the default FirebaseDatabase instance.

Returns
FirebaseDatabase

A FirebaseDatabase instance.

getInstance

java-static fun getInstance(app: FirebaseApp): FirebaseDatabase

Gets an instance of FirebaseDatabase for a specific FirebaseApp.

Parameters
app: FirebaseApp

The FirebaseApp to get a FirebaseDatabase for.

Returns
FirebaseDatabase

A FirebaseDatabase instance.

getInstance

java-static fun getInstance(url: String): FirebaseDatabase

Gets a FirebaseDatabase instance for the specified URL.

Parameters
url: String

The URL to the Firebase Database instance you want to access.

Returns
FirebaseDatabase

A FirebaseDatabase instance.

getInstance

synchronized java-static fun getInstance(app: FirebaseApp, url: String): FirebaseDatabase

Gets a FirebaseDatabase instance for the specified URL, using the specified FirebaseApp.

Parameters
app: FirebaseApp

The FirebaseApp to get a FirebaseDatabase for.

url: String

The URL to the Firebase Database instance you want to access.

Returns
FirebaseDatabase

A FirebaseDatabase instance.

getReference

fun getReference(): DatabaseReference

Gets a DatabaseReference for the database root node.

Returns
DatabaseReference

A DatabaseReference pointing to the root node.

getReference

fun getReference(path: String): DatabaseReference

Gets a DatabaseReference for the provided path.

Parameters
path: String

Path to a location in your FirebaseDatabase.

Returns
DatabaseReference

A DatabaseReference pointing to the specified path.

getReferenceFromUrl

fun getReferenceFromUrl(url: String): DatabaseReference

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: String

A URL to a path within your database.

Returns
DatabaseReference

A DatabaseReference for the provided URL.

getSdkVersion

java-static fun getSdkVersion(): String
Returns
String

The semver version for this build of the Firebase Database client

goOffline

fun goOffline(): Unit

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

goOnline

fun goOnline(): Unit

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

purgeOutstandingWrites

fun purgeOutstandingWrites(): Unit

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.

setLogLevel

synchronized fun setLogLevel(logLevel: Logger.Level): Unit

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: Logger.Level

The desired minimum log level

setPersistenceCacheSizeBytes

synchronized fun setPersistenceCacheSizeBytes(cacheSizeInBytes: Long): Unit

By default Firebase Database will use up to 10MB of disk space to cache data. If the cache grows beyond this size, Firebase Database will start removing data that hasn't been recently used. If you find that your application caches too little or too much data, call this method to change the cache size. This method must be called before creating your first Database reference and only needs to be called once per application.

Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or greater than 100 MB are not supported.

Parameters
cacheSizeInBytes: Long

The new size of the cache in bytes.

setPersistenceEnabled

synchronized fun setPersistenceEnabled(isEnabled: Boolean): Unit

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: Boolean

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

useEmulator

fun useEmulator(host: String, port: Int): Unit

Modifies this FirebaseDatabase instance to communicate with the Realtime Database emulator.

Note: Call this method before using the instance to do any database operations.

Parameters
host: String

the emulator host (for example, 10.0.2.2)

port: Int

the emulator port (for example, 9000)

Public properties

app

val appFirebaseApp!