I have uploaded to database sample JSON and customize a value just to see the code get executed meaning to make sure my query get a match and return back the object. So here is my implementation.
Query personQuery = myRef.orderByChild("mCalculateLeftEyeSizeWidth")
.startAt(mCalculateLeftEyeSizeWidth())
.limitToFirst(1);
personQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.exists()){
Log.d(TAG, "onChildAdded:" + dataSnapshot.getKey());
Person person = dataSnapshot.getValue(Person.class);
Log.d(TAG,"Person name:" + person.getName());
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.exists()) {
Log.d(TAG, "onChildChanged:" + dataSnapshot.getKey());
Person person = dataSnapshot.getValue(Person.class);
Log.d(TAG, "Person name:" + person.getName());
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
Log.d(TAG, "onChildRemoved:" + dataSnapshot.getKey());
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.exists()) {
Log.d(TAG, "onChildMoved:" + dataSnapshot.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "DatabaseError:" + databaseError.getMessage());
}
});
If I am running debug After Analyze image I see that the query do all the stuff here:
Query personQuery = myRef.orderByChild("mCalculateLeftEyeSizeWidth")
.startAt(mCalculateLeftEyeSizeWidth())
.limitToFirst(1);
Get the calculation correctly, I am looking at the debug personQuery and everything seems to be fine.
but when I moving to the next part:personQuery.addChildEventListener
It jumps over it and my entire function executed is ended. What should I expect here? Does it now listen to every change? Does it mean it did not find a match even if I made sure manually that the same value exist? Do I need to actually upload another JSON file to trigger onChildAdded or onChildChanged?
My logic is the Permitted user take a photo. my app does face recognition, do math calculation, then query to the Firebase database to find a match according to value and suppose to return the person object back to the Android device for presentation. The mobile device only doing a query and return match, it does not update the Database with new records, this I do manually. So I am not sure if the "Listen" part gets a trigger or not.