I am new to Firebase Real-time Database and don't have an idea that how to fetch only the recent updated object from the table.
I have tried using "ChildEventListener" but when I initialize the Listener for the first time it fetches the last row from the database. It should not be fetched if it was not updated. I want object only when it is updated or newly added. I have done this,
databaseReference.child("last_chat").orderByChild("s_id").equalTo(preference.getUserData().getId()).limitToLast(1).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.e("dataSnapShot", dataSnapshot.toString() + " " + s);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.e("dataSnapShotChagned", dataSnapshot.toString() + " " + s);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.e("dataSnapShotRemoved", dataSnapshot.toString());
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("onCalcnelle", databaseError.toString());
}
});
Thank you in advance.