What Is The Best Way To Check The Existence Of Every Child In One Node?
FirebaseDatabase.getInstance().getReference('Block').addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot
Solution 1:
Just traverse to the path specified using child
. You will get no data if the path doesn't exist.
FirebaseDatabase.getInstance().getReference("Block")
.child("MyUUID")
.child("specificUUID")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
// ... Do something
} else {
call_method();
}
// ... Other code
}
Solution 2:
Try this:
Firebaseuser user=FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Block");
ref.child(user.getUid()).addListenerForSingleValueEvent(newValueEventListener() {
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){
//checks first uidif(dataSnapshot.hasChild(seconduid){
//checks if seconduid is therefor(DataSnapshotdatas:dataSnapshot.getChildren()){
String blocks=datas.child("block").getValue().toString();
}
}
}
}
@OverridepublicvoidonCancelled(DatabaseError databaseError) {
}
});
This will check the first uid if(dataSnapshot.exist())
after that it will check if that uid
node has the second uid that you provide if(dataSnapshot.hasChild(seconduid){
then you will iterate and get the node block
Post a Comment for "What Is The Best Way To Check The Existence Of Every Child In One Node?"