I'm cycling through some children in firebase to see if the value of a key exists, and in my addListenerForSingleValueEvent function the key is found and a global boolean is set to true. However, after the function, the variable is set as false so the program does not enter the second if statement.
referenceClasses.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
if (snapshot.getKey().compareTo(combinedString) == 0) {
found = true;
break;
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) { }
});
if(found) {
//...
}
I know found is set to true within the addListenerForSingleValueEvent through various inputs to my database. the boolean is instantiated as
boolean found;
globally, before any other functions. I even tried to implement two functions, one which sets the boolean and another which returns it but I ended up with the same results of the boolean being true within addListenerForSingleValueEvent and false in the if statement. Any ideas?