Cristian.R Cristian.R - 1 year ago 162
Android Question

Android: Firebase ChildEventListener() not working

I am working in my app with Firebase and I tried to use onChildAdded() callback but I think I am doing something wrong because I get no response.

* Constructor
private FirebaseManager(Context context) {
mFirebaseRef = new Firebase(FIREBASE_URL);

public void checkUsers() {
Firebase checkRef = mFirebaseRef.child("/data/users/");
// Also tried
// Firebase checkRef = mFirebaseRef.child("data").child("users");
checkRef.addChildEventListener(new ChildEventListener() {
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.d(TAG,"New child added");

public void onChildChanged(DataSnapshot dataSnapshot, String s) {


public void onChildRemoved(DataSnapshot dataSnapshot) {


public void onChildMoved(DataSnapshot dataSnapshot, String s) {


public void onCancelled(FirebaseError firebaseError) {



In onCreate() of my MainActivity I authenticate the user and the call checkUsers(). After that I manually add a new user in database. But I get nothing in log.
This is the json structure:

enter image description here

What am I doing wrong?

Answer Source

I got it. There was a concurrency problem. I called checkUsers() in onCreate() of the MainActivity but it needs to be called in onAuthenticated(), because the user was authenticated after the method checkUsers() tried to set listeners.

I got a LOG about the failure of accessing database:

W/SyncTree: Listen at / failed: FirebaseError: Permission denied

but didn't seen it because I was following a specific TAG with logcat Search.