I am new to firebase via Android(Java) and was wondering how to check if a user already exists in a database of the following format:
gdb-2fbgg{
u
Declare hander with delay as per your preference in onCreate() and call a method from here
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
ok();
}
},3000);
Then create this method body
public void ok(){
Toast.makeText(this, "Count is : "+adapter.getItemCount(), Toast.LENGTH_SHORT).show();
}
Now you will get count after specfied delay
Use .child("Michael").exists()
method or .hasChild("Michael")
with SingleValueEvent within onDataChange
DatabaseReference root = FirebaseDatabase.getInstance().getReference();
DatabaseReference users = root.child("users");
users.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.child("Michael").exists()) {
// run some code
}else{
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});