first you have to add your project to firebase, then import the corresponding libraries in this case would be the FireBaseDatabase libraries, now if we go to the Code, you can do it in two ways
fReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//si hay cambios realizados
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}});
You can also do it with the ChildListener event
ChildEventListener listener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String value = dataSnapshot.getValue(String.class);//si se agrego un nuevo hijo los valores de ese hijo estaran en la variable String value
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
and in your Oncreate
fReference.addChildEventListener(listener);
the add function shows you all the ones that are added in real time, the changed function shows you immediately the changes made in real time the move if the file was moved or the data is removed because if they were deleted
I hope I have helped you;) regards