I've been trying to extract informations from Firebase Realtime database to my desktop Java application and I'm confused with how the ChildeventListener
works so;
public void getInformation(){
DatabaseReference ref = FirebaseDatabase.getInstance()
.getReference().child("Users/Informatique/LFI1");
Query myq = ref.orderByChild("Presences");
myq.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
Map <String, String> map = new HashMap <String, String>();
map = (Map<String, String>) snapshot.child("Presences").getValue();
for(Map.Entry<String,String> entry : map.entrySet()){
System.out.println(entry.getValue());
list.add(entry.getValue());
}
}
});
System.out.println(list.size());
}
The values i get in the output is what I need but the list's size after all that is 0
and can't be use else where yet if you check the size inside the onChildAdded method you get the right one.
0
< 12345678 Skander Maranissi LFI1 Wed May 02 15:52:03 GMT+01:00 2018 >
< 12345678 Mohsen Yajour LFI1 Wed May 02 15:09:32 GMT+01:00 2018 >
< 12345678 Lebron James LFI1 Wed May 02 16:51:35 GMT+01:00 2018 >
< 12345678 Lebron James LFI1 Sat May 05 12:54:02 GMT+01:00 2018 >
How is it printing the list's size then looping through the map; this is what's not clear in my mind about how Listeners work. Thanks a lot.