I created a project in which I need to listen to multiple database locations at once.
{
"A": [data-a],
"B": [data-b],
"C": [data-c]
}
Whenever anything gets changed, added or deleted at location A
, B
or C
I want to display the action which happened inside a ListView
in Android.
For one location I have been able to achieve this by adding the following code to my project.
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("A");
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
//Child got added
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
//Child got changed
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
//Child got removed
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
//Child got moved
}
@Override
public void onCancelled(DatabaseError databaseError) {
//Some error happened
}
});
Now to my question. Do I need multiple listeners for each location or can I somehow get notified about all changes in a simpler way?