Firebase retrieves all data at application startup

I am having trouble finding any information using the documentation on firebase and google on how to get all the data when the application starts.

Suppose I want to get all of the following data when an application starts without any event. and store in an ArrayList. Say ArrayList<Quote> , and the quote has three fields (int id, String text, String author).

 [{ "id" : 1, "text": "There are 1,411 tigers left in India.", "author": "NULL" }, { "id" : 2, "text": "The Greek for \"left-handed\" also means \"better\".", "author": "NULL" }] 

According to the documentation, there is an onDataChange () method, but the application does not change any data. How to capture all data and save in ArrayList<Quote> which I can pass to user adapter.

+5
source share
2 answers

Data storage

The Firebase Realtime database synchronizes and stores a local copy of the data for active listeners. In addition, you can sync specific locations.

 DatabaseReference scoresRef = FirebaseDatabase.getInstance().getReference("scores"); scoresRef.keepSynced(true); 

The client will automatically download data in these places and keep them in sync, even if there are no active listeners in the link. You can disable synchronization with the next line of code.

Refer to this document for more information; https://firebase.google.com/docs/database/android/offline-capabilities

+2
source

The onDataChange() method is called directly when the listener is connected ( ValueEventListener or ChildEventListener ), so you do not need to make any changes to the data to call this method.

From Firebase documentation - retrieving data on Android

This method is run once when the listener connects and again every time the data, including children, is changed.

+2
source

All Articles