Stay organized with collections Save and categorize content based on your preferences.
DataSnapshotpublic class 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
, addChildEventListener
, or addListenerForSingleValueEvent
. 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
).
public @NonNull DataSnapshot child(@NonNull String path)
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.
Parameters@NonNull String path
A relative path to the location of child data
existspublic boolean exists()
Returns true if the snapshot contains a non-null value.
Returnsboolean
True if the snapshot contains a non-null value, otherwise false
getChildrenpublic @NonNull Iterable<DataSnapshot> getChildren()
Gives access to all of the immediate children of this snapshot. Can be used in native for loops:
for (DataSnapshot child : parent.getChildren()) { ... }getChildrenCount
public long getChildrenCount()Returns
long
The number of immediate children in the this snapshot
getKeypublic @Nullable String getKey()Returns
@Nullable String
The key name for the source location of this snapshot or null if this snapshot points to the database root.
getPrioritypublic @Nullable Object getPriority()
Returns the priority of the data contained in this snapshot as a native type. Possible return types:
Double
String
Note that null is also allowed
Returns@Nullable Object
the priority of the data contained in this snapshot as a native type
getValuepublic @Nullable Object getValue()
getValue() returns the data contained in this snapshot as native types. The possible types returned are:
Boolean
String
Long
Double
Map<String, Object>
List<Object>
This list is recursive; the possible types for
java.lang.Object
in the above list is given by the same list. These types correspond to the types available in JSON.
Returns@Nullable Object
The data contained in this snapshot as native types or null if there is no data at this location.
getValuepublic @Nullable T <T> getValue(@NonNull GenericTypeIndicator<T> t)
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 java.util.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
Returns@Nullable T
A properly typed collection, populated with the data from this snapshot, or null if there is no data at this location.
getValuepublic @Nullable Object getValue(boolean useExportFormat)
getValue() returns the data contained in this snapshot as native types. The possible types returned are:
Boolean
String
Long
Double
Map<String, Object>
List<Object>
This list is recursive; the possible types for
java.lang.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.
Parametersboolean useExportFormat
Whether or not to include priority information
Returns@Nullable Object
The data in native types, along with its priority, or null if there is no data at this location.
getValuepublic @Nullable T <T> getValue(@NonNull Class<T> valueType)
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:
An example class might look like:
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);Parameters
<T>
The type to return. Implicitly defined from the class passed in
@NonNull Class<T> valueType
The class into which this snapshot should be marshalled
Returns@Nullable T
An instance of the class passed in, populated with the data from this snapshot, or null if there is no data at this location.
hasChildpublic boolean hasChild(@NonNull String path)
Can be used to determine if this DataSnapshot has data at a particular location
Parameters@NonNull String path
A relative path to the location of child data
Returnsboolean
Whether or not the specified child location has data
hasChildrenpublic boolean hasChildren()
Indicates whether this snapshot has any children
Returnsboolean
True if the snapshot has any children, otherwise false
Extension functions DatabaseKt.getValuepublic final T <T extends Object> DatabaseKt.getValue(@NonNull DataSnapshot receiver)
Returns the content of the DataSnapshot converted to a POJO.
Supports generics like List<> or Map<>. Use @JvmSuppressWildcards to force the compiler to use the type T
, and not ? extends T
.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-21 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-21 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4