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.
问题:
回答1:
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.
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.