bhavs
bhavs

Reputation: 2291

firebase child exists or not in android

My question is similar to the question posted here

  1. I have a Firebase path called for a users table, say appname/users
  2. I want to see if a user exists.
  3. I obtain a reference: Firebase users = ref.child('users');

I am wondering if there is an equivalent Java code similar to the javascript answer provided. I ask this because in the latest version of Firebase-client that I am using I am unable to find the method once(), which has been called to see if a child exists or not.

EDIT 1:

I am using the Eclipse IDE for development and I have download the firebase jar from the location specified in the web page. I am unable to use a couple of methods as I do not see any of them being specified.

Firebase ref = new Firebase(url);
Firebase usersRef = ref.child("users");

When I try to use the method once()/ hasChild() the IDE does not show any of these methods being available. I am not sure if it is only at my end or if I need to download and use another jar? here

Any suggestions?

Upvotes: 3

Views: 6152

Answers (1)

Greg Soltis
Greg Soltis

Reputation: 1434

I think what you're looking for is addListenerForSingleValueEvent. It is the Java equivalent to the 'once' function in javascript. In addition, the 'hasChild' method is available on the DataSnapshot class, which will be provided in the callback to your listener. In general, you can find all of the Java API documented here: https://www.firebase.com/docs/java-api/javadoc/index.html

Upvotes: 4

Related Questions