Checking if a particular value exists in the Firebase database

前端 未结 6 1971
孤城傲影
孤城傲影 2020-11-22 07:04

I am making an Android application using Firebase realtime database. When a new user registers on my app, that user\'s data is saved in the Firebase database. <

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 07:22

    Since you have already got a solution to your problem, I will try to explain why your code was not working.

     DatabaseReference fdbRefer = FirebaseDatabase.getInstance().getReference("Users/"+username);
    

    You might be thinking that in the above statement fdbRefer will be null if "Users/"+username is not present in the database.
    But actually, this statement will only store a path to the specified field in getReference(). So when you check for fdbRef!=null, it is always true because fdbRefer will hold value something like 'https://.firebase.com/Users/Nick123.

提交回复
热议问题