确定 Firebase 是否没有使用 startAt 和 endAT 下载数据 [英] Determining if Firebase didn't download data with startAt and endAT

查看:26
本文介绍了确定 Firebase 是否没有使用 startAt 和 endAT 下载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Firebase 下载数据.问题是我正在根据时间戳下载数据.如果我正在填充的 ListView 中只有一项,我想从 Firebase 获取接下来两个小时的数据,如果过去两个小时没有任何数据,我想要获得接下来的两个小时的数据,依此类推,直到我获得一些额外的数据.问题是我不完全知道如何确定 Firebase 是否实际下载了数据.因为如果下载了数据,我可以为我的 listView 使用 OnScrollListener 来下载更多数据,因为在那之后它可以滚动.任何帮助将不胜感激.

I'm trying to download data with Firebase. The issue is that I'm downloading the data based off of a timestamp. If their is only one item in my ListView that I'm populating, I want to get the next two hours worth of data from Firebase and if there isn't any data from the last two hours, I want to get the next two hours of data and so on until I get some additional data. The issue is that I don't exactly know how to determine if Firebase actually downloaded data. Because if data was downloaded, I can use an OnScrollListener for my listView to download more data since it will be scrollable after that point. Any help would be appreciated.

推荐答案

您无法知道从数据库中获取数据何时完成,因为Firebase 是实时数据库,并且获取数据可能永远不会完成.这就是为什么命名为实时数据库的原因,因为在任何时候都可以更改数据库,可以添加或删除项目.

You cannot know when getting the data from the database is completed becase Firebase is a real-time database and getting data might never complete. That's why is named a realtime database because in any momemnt the database can be changed, items can be added or deleted.

部分了解特定位置是否拥有所有数据的唯一方法是对其执行单个值"类型查询.即便如此,在调用该侦听器后数据可能会发生变化,因此您真正拥有的只是特定时刻的快照.

The only way to partially know if you have all the data at a particular location is to perform a single 'value' type query on it. Even then, the data may change after that listener is invoked, so all you really have is a snapshot at a particular moment in time.

仅当您在数据库中写入更新数据时才可以使用CompletionListener,并且您会在操作完成时收到通知Firebase 服务器已确认,但在读取数据时无法使用此接口.

You can use a CompletionListener only when you write or update data in your database and you'll be notified when the operation has been acknowledged by the Firebase servers but you cannot use this interface when reading data.

这篇关于确定 Firebase 是否没有使用 startAt 和 endAT 下载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆