I need to return a read data from Firebase. Here is the code:
private String getInfo(DatabaseReference reference) {
String string = "";
reference.child("xxx").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
string = snapshot.getValue().toString();
// here the log display the correct value I need
Log.i("Log", string);
}
onCancelled() ...
}
});
return string; // HERE THE VALUE IS NULL!!!!
As written above the log show the correct value, but when I try to return it its value becomes null.