android - 检查 Firebase android 中的最后一个 child 是否

标签 android firebase firebase-realtime-database

<分区>

如何在从 Firebase 检索数据时知道这是否是最后一个 child ?

最佳答案

根据 Firebase documentation :

public DatabaseReference getParent()
A DatabaseReference to the parent location, or null if this instance references the root location

public DatabaseReference getRoot()
A reference to the root location of this Firebase Database

因此,您可以在 DatabaseReference 对象上使用 getRoot() 以始终转到根目录,或者使用 getParent() 直到得到 null。

您应该以扁平化结构构建数据,这样您就不会对数据的结束位置 ( documentation ) 感到困惑:

Avoid nesting data

Because the Firebase Realtime Database allows nesting data up to 32 levels deep, you might be tempted to think that this should be the default structure. However, when you fetch data at a location in your database, you also retrieve all of its child nodes. In addition, when you grant someone read or write access at a node in your database, you also grant them access to all data under that node. Therefore, in practice, it's best to keep your data structure as flat as possible.

关于android - 检查 Firebase android 中的最后一个 child 是否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40338242/

相关文章:

ios - 在 Firebase 中对大量数据进行分页的最有效方法

android - 如何检索 Firebase 中字段的值?

android - 将视频插入 MediaStore

android - 如何创建一个允许较大 child 的 View ?

java - 通过 HttpGet 从 Web 服务读取 char[] — 奇怪的行为

swift - Firebase Firestore 弄乱了数组的顺序

java - 查询 firebase 数据库时如何将项目追加到 OnDataChange 内的 ArrayList

android - 如何填充 Java 项目中每个函数的 log/println 调用?

android - DataSnapshot 手动创建

java - Android Firebase java.lang.StackOverflowError : stack size 8MB error when user is uploading an image