Currently I have a problem with a Firebase query that is not executing the onChildAdded
method. I implemented a callback to handle the asynchronous nature of Firebase queries, therefore, after having populated thesectoresMayorEspera
and localizacionMayorEspera
ArrayLists inside the onChildAdded
method using data contained in the dataSnapshot
, the buscarEspera
method should be executed with the previous ArrayLists as parameters.
The problem arises when onChildAdded
method is "ignored" and the buscarEspera
method is passed empty ArrayLists.
public void busquedaEspera(final MiCallbackEspera miCallbackEspera) {
if (cantidadBuses > 1) {
Firebase sectoresMasTiempo = new Firebase("https://brilliant-heat-7882.firebaseio.com/SectoresDatos/").child(String.valueOf(sectorOrigenBus));
sectoresMasTiempo.orderByChild("espera").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
sectoresMayorEspera.add(dataSnapshot.getKey());
HashMap hashMap = (HashMap) dataSnapshot.getValue();
HashMap localizacionHashMap = (HashMap) hashMap.get("localizacionEspera");
localizacionMayorEspera.add(new LatLng((double) localizacionHashMap.get("latitude"), (double) localizacionHashMap.get("longitude")));
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
miCallbackEspera.buscarEspera(sectoresMayorEspera, localizacionMayorEspera);
}
I am new to coding (obviously new to Android, to Java, to...) I'd appreciate your help to tackle this one.