I am working on a project on Android Studio with libGDX and I have connected the game to firebase which is working perfectly.
When I am trying to fetch some data, the firebase returns proper expected values, but the function is returning a null value.
public String fetchData(String id)
{
reference = FirebaseDatabase.
getInstance().getReference("Users").
child(FirebaseAuth.getInstance().getCurrentUser().getUid());
reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
s = snapshot.child(id).getValue(String.class); //Here if we print s it gives the desired output.
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
return s; // But here the function is returning null.
}
@Override
public String Background_Active() {
return fetchData("Background Active"); //Here I am calling the above function
}
If someone is aware of the solution to this issue, please do help me out.