public final class SimpleFirebase extends Object
Activity, so you
must call SimpleFirebase.with(yourActivity) first.
By design of Firebase, most methods are asynchronous
(get, set, signIn, push, watch);
they return immediately and will notify your code when their results are available
by contacting an appropriate listener.
The most common intended usage pattern is to make your activity implement GetListener,
SetListener, SignInListener, etc. or to write small inner classes that implement
these interfaces.
We recommend you also implement ErrorListener so that you can see when operations fail on
your database, or at least call setLogging(true) to turn on a default error listener.
| Modifier and Type | Class and Description |
|---|---|
static interface |
SimpleFirebase.ErrorListener
An event listener that can respond to database errors.
|
static interface |
SimpleFirebase.GetListener
An event listener that can respond to the result of get() calls.
|
static interface |
SimpleFirebase.PushListener
An event listener that can respond to the result of push() or pushById() calls.
|
static interface |
SimpleFirebase.SetListener
An event listener that can respond to the result of set() calls.
|
static interface |
SimpleFirebase.SignInListener
An event listener that can respond to the result of signIn() calls.
|
static interface |
SimpleFirebase.TransactionListener
An event listener that can respond to the result of transaction() calls.
|
static interface |
SimpleFirebase.WatchListener
An event listener that can respond to the result of watch() calls.
|
| Constructor and Description |
|---|
SimpleFirebase() |
| Modifier and Type | Method and Description |
|---|---|
DatabaseReference |
child(String queryText)
Returns a child of the overall database; equivalent to Firebase's child() method
or the SimpleFirebase query() method.
|
void |
clearLastDatabaseError()
Clears this object's record of any past database error.
|
SimpleFirebase |
get(Query ref)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
get(Query ref,
SimpleFirebase.GetListener listener)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
get(String path)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
get(String path,
SimpleFirebase.GetListener listener)
Initiates a request to retrieve the data at the given path in the database.
|
FirebaseUser |
getCurrentUser()
Returns the user who is currently signed in, or null if no user is signed in.
|
boolean |
hasLastDatabaseError()
Returns true if there has been a database error that has not been cleared.
|
boolean |
isSignedIn()
Returns true if a user is currently signed in.
|
DatabaseError |
lastDatabaseError()
Returns the last database error that occurred, or null if no error has occurred.
|
SimpleFirebase |
login(String username,
String password)
Signs in with the given username and password; an alias for signIn().
|
DatabaseReference |
push(String path)
Adds a new object with a randomly-generated unique string key at the given path in the database,
and returns that newly pushed object.
|
SimpleFirebase |
pushById(String path)
Adds a new object with a new unique integer ID key at the given path in the database.
|
SimpleFirebase |
pushById(String path,
Object value)
Adds a new object with a new unique integer ID key at the given path in the database.
|
SimpleFirebase |
pushById(String path,
Object value,
SimpleFirebase.PushListener listener)
Adds a new object with a new unique integer ID key at the given path in the database.
|
SimpleFirebase |
pushById(String path,
SimpleFirebase.PushListener listener)
Adds a new object with a new unique integer ID key at the given path in the database.
|
DatabaseReference |
query(String queryText)
Performs a query on the Firebase database.
|
SimpleFirebase |
set(String path,
Object value)
Sets the given location in the database to store the given value.
|
SimpleFirebase |
set(String path,
Object value,
SimpleFirebase.SetListener listener)
Sets the given location in the database to store the given value.
|
SimpleFirebase |
set(String path,
String key,
Object value)
Sets the given location in the database to store the given value.
|
SimpleFirebase |
set(String path,
String key,
Object value,
SimpleFirebase.SetListener listener)
Sets the given location in the database to store the given value.
|
SimpleFirebase |
setErrorListener(SimpleFirebase.ErrorListener listener)
Sets the given listener object to be notified of future database errors.
|
SimpleFirebase |
setLogging(boolean logging)
Sets whether the SimpleFirebase library should print log messages for debugging.
|
SimpleFirebase |
signIn(String email,
String password)
Signs in with the given username and password.
|
SimpleFirebase |
signIn(String email,
String password,
SimpleFirebase.SignInListener listener)
Signs in with the given username and password.
|
SimpleFirebase |
signInAnonymously()
Signs in to the database anonymously.
|
SimpleFirebase |
signInAnonymously(SimpleFirebase.SignInListener listener)
Signs in to the database anonymously.
|
SimpleFirebase |
signInWithCredential(AuthCredential authCredential)
Signs in with the given username and password.
|
SimpleFirebase |
signInWithCredential(AuthCredential authCredential,
SimpleFirebase.SignInListener listener)
Signs in with the given username and password.
|
SimpleFirebase |
signInWithCustomToken(String token)
Signs in to the database using the given custom token.
|
SimpleFirebase |
signInWithCustomToken(String token,
SimpleFirebase.SignInListener listener)
Signs in to the database using the given custom token.
|
SimpleFirebase |
signOut()
Signs out of the database, if currently signed in.
|
SimpleFirebase |
transaction(String path)
Initiates a request to perform a transaction on the data at the given path in the database.
|
SimpleFirebase |
transaction(String path,
SimpleFirebase.TransactionListener listener)
Initiates a request to perform a transaction on the data at the given path in the database.
|
SimpleFirebase |
watch(Query ref)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
watch(Query ref,
SimpleFirebase.GetListener listener)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
watch(String path)
Initiates a request to retrieve the data at the given path in the database.
|
SimpleFirebase |
watch(String path,
SimpleFirebase.GetListener listener)
Initiates a request to retrieve the data at the given path in the database.
|
static SimpleFirebase |
with(Context context)
Returns a new SimpleFirebase instance using the given activity or other context.
|
public static SimpleFirebase with(Context context)
public DatabaseReference child(String queryText)
query(String)public void clearLastDatabaseError()
public SimpleFirebase get(String path)
path - absolute database path such as "foo/bar/baz"public SimpleFirebase get(String path, SimpleFirebase.GetListener listener)
path - absolute database path such as "foo/bar/baz"listener - object to notify when the data has arrivedpublic SimpleFirebase get(Query ref)
ref - a Query object containing an absolute database referencepublic SimpleFirebase get(Query ref, SimpleFirebase.GetListener listener)
ref - a Query object containing an absolute database referencelistener - object to notify when the data has arrivedpublic FirebaseUser getCurrentUser()
public boolean hasLastDatabaseError()
public boolean isSignedIn()
public DatabaseError lastDatabaseError()
public SimpleFirebase login(String username, String password)
public DatabaseReference push(String path)
path - absolute database path such as "foo/bar/baz"public SimpleFirebase pushById(String path)
path - absolute database path such as "foo/bar/baz"public SimpleFirebase pushById(String path, Object value)
path - absolute database path such as "foo/bar/baz"value - value to store at this pathpublic SimpleFirebase pushById(String path, SimpleFirebase.PushListener listener)
path - absolute database path such as "foo/bar/baz"listener - object to notify when the data has arrivedpublic SimpleFirebase pushById(String path, Object value, SimpleFirebase.PushListener listener)
path - absolute database path such as "foo/bar/baz"value - value to store at this pathlistener - object to notify when the data has arrivedpublic DatabaseReference query(String queryText)
SimpleFirebase fb = SimpleFirebase.with(this);
fb.get(fb.query("foo/bar/baz")
.orderByChild("quux")
.limitToFirst(1));
queryText - absolute path in database such as "foo/bar/baz"public SimpleFirebase set(String path, Object value)
path - an absolute database path such as "foo/bar/baz"value - the value to store there in the databasepublic SimpleFirebase set(String path, String key, Object value)
path - an absolute database path such as "foo/bar/baz"key - child key name within that path, such as "quux" to indicate "foo/bar/baz/quux"value - the value to store there in the databasepublic SimpleFirebase set(String path, Object value, SimpleFirebase.SetListener listener)
path - an absolute database path such as "foo/bar/baz"value - the value to store there in the databasepublic SimpleFirebase set(String path, String key, Object value, SimpleFirebase.SetListener listener)
path - an absolute database path such as "foo/bar/baz"key - child key name within that path, such as "quux" to indicate "foo/bar/baz/quux"value - the value to store there in the databasepublic SimpleFirebase setErrorListener(SimpleFirebase.ErrorListener listener)
public SimpleFirebase setLogging(boolean logging)
public SimpleFirebase signIn(String email, String password)
email - email address or user name such as "jsmith12"password - user password such as "abc123"public SimpleFirebase signIn(String email, String password, SimpleFirebase.SignInListener listener)
email - email address or user name such as "jsmith12"password - user password such as "abc123"public SimpleFirebase signInAnonymously()
public SimpleFirebase signInAnonymously(SimpleFirebase.SignInListener listener)
public SimpleFirebase signInWithCredential(AuthCredential authCredential)
public SimpleFirebase signInWithCredential(AuthCredential authCredential, SimpleFirebase.SignInListener listener)
public SimpleFirebase signInWithCustomToken(String token)
public SimpleFirebase signInWithCustomToken(String token, SimpleFirebase.SignInListener listener)
public SimpleFirebase signOut()
public SimpleFirebase transaction(String path)
path - absolute database path such as "foo/bar/baz"public SimpleFirebase transaction(String path, SimpleFirebase.TransactionListener listener)
path - absolute database path such as "foo/bar/baz"listener - object to notify when the mutable data has arrivedpublic SimpleFirebase watch(String path)
path - absolute database path such as "foo/bar/baz"public SimpleFirebase watch(String path, SimpleFirebase.GetListener listener)
path - absolute database path such as "foo/bar/baz"listener - object to notify when the data has arrivedpublic SimpleFirebase watch(Query ref)
ref - a Query object representing an absolute database pathpublic SimpleFirebase watch(Query ref, SimpleFirebase.GetListener listener)
ref - a Query object representing an absolute database pathlistener - object to notify when the data has arrived