How to check if a value exists in firebase database - android

后端 未结 2 547
名媛妹妹
名媛妹妹 2020-12-18 14:18

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         


        
相关标签:
2条回答
  • 2020-12-18 15:03

    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

    0 讨论(0)
  • 2020-12-18 15:06

    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) {
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题