I am trying to return a boolean but the value returned is always false, i.e. 0 in this case.
The check variable is an instance variable and the below function is getting called when a button is pressed.
private boolean checkAnswerSubmission() {
DatabaseReference answerDatabase = FirebaseDatabase.getInstance().getReference().child("userPuzzleHistory").child(uid);
answerDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(String.valueOf(imagename))) {
check = 1;
} else {
check = 0;
}
//here the value check is working fine but the value cannot be returned from here.
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
//here the value returned is always 0
if (check == 1)
return true;
else
return false;
}