Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 206

Check if child exist in firebase database and return true or false [duplicate]

$
0
0

I want to create method that will check if a child is present or not in firebase database and returns the value true or false accordingly. here's my code

public boolean check_if_child_exist(DatabaseReference reference, String child){        boolean if_exist;        reference.addListenerForSingleValueEvent(new ValueEventListener(){            @Override            public void onDataChange(DataSnapshot datasnapshot) {                if(datasnapshot.hasChild(child)) {                    if_exist = true;                }            }            @Override            public void onCancelled(DatabaseError error) {                if_exist = false;            }        });        return if_exist;    }

I have tried below code but it didn't work

if(datasnapshot.hasChild(child)) {    return true;}

Viewing all articles
Browse latest Browse all 206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>