| java.lang.Object | |
| ↳ | com.google.firebase.database.DataSnapshot |
A DataSnapshot instance contains data from a Firebase Database location. Any time you read
Database data, you receive the data as a DataSnapshot.
DataSnapshots are passed to the methods in listeners that you attach with
addValueEventListener(ValueEventListener),
addChildEventListener(ChildEventListener), or
addListenerForSingleValueEvent(ValueEventListener).
They are efficiently-generated immutable copies of the data at a Firebase Database location.
They can't be modified and will never change. To modify data at a location,
use a DatabaseReference reference
(e.g. with setValue(Object)).
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Get a DataSnapshot for the location at the specified relative path.
| |||||||||||
Returns true if the snapshot contains a non-null value.
| |||||||||||
Gives access to all of the immediate children of this snapshot.
| |||||||||||
Returns the priority of the data contained in this snapshot as a native type.
| |||||||||||
Used to obtain a reference to the source location for this snapshot.
| |||||||||||
getValue() returns the data contained in this snapshot as native types.
| |||||||||||
Due to the way that Java implements generics, it takes an extra step to get back a properly-typed Collection.
| |||||||||||
getValue() returns the data contained in this snapshot as native types.
| |||||||||||
This method is used to marshall the data contained in this snapshot into a class of your choosing.
| |||||||||||
Can be used to determine if this DataSnapshot has data at a particular location
| |||||||||||
Indicates whether this snapshot has any children
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Get a DataSnapshot for the location at the specified relative path. The relative path can either be a simple child key (e.g. 'fred') or a deeper slash-separated path (e.g. 'fred/name/first'). If the child location has no data, an empty DataSnapshot is returned.
| path | A relative path to the location of child data |
|---|
Returns true if the snapshot contains a non-null value.
Gives access to all of the immediate children of this snapshot.
Can be used in native for loops:
for (DataSnapshot child : parent.getChildren()) {
...
}
Returns the priority of the data contained in this snapshot as a native type. Possible return types:
Used to obtain a reference to the source location for this snapshot.
getValue() returns the data contained in this snapshot as native types. The possible types returned are:
Object
in the above list is given by the same list. These types correspond to the
types available in JSON.
If useExportFormat is set to true, priority information will be included in the output.
Priority information shows up as a .priority key in a map. For data that would not otherwise
be a map, the map will also include a .value key with the data.| useExportFormat | Whether or not to include priority information |
|---|
Due to the way that Java implements generics, it takes an extra step to get back a properly-typed Collection.
So, in the case where you want a List of Message instances, you will need to do something like
the following:
GenericTypeIndicator<List<Message>> t = new GenericTypeIndicator<List<Message>>() {};
List<Message> messages = snapshot.getValue(t);
It is important to use a subclass of GenericTypeIndicator. See GenericTypeIndicator for more details| t | A subclass of GenericTypeIndicator indicating the type of generic collection to be returned. |
|---|
getValue() returns the data contained in this snapshot as native types. The possible types returned are:
Object
in the above list is given by the same list. These types correspond to the
types available in JSON.This method is used to marshall the data contained in this snapshot into a class of your choosing. The class must fit 2 simple constraints:
class Message {
private String author;
private String text;
private Message() {}
public Message(String author, String text) {
this.author = author;
this.text = text;
}
public String getAuthor() {
return author;
}
public String getText() {
return text;
}
}
// Later
Message m = snapshot.getValue(Message.class);
| valueType | The class into which this snapshot should be marshalled |
|---|
Can be used to determine if this DataSnapshot has data at a particular location
| path | A relative path to the location of child data |
|---|
Indicates whether this snapshot has any children