Reputation: 135
I'm trying to make an app that will have multiple users and I need that all of them share the same database. So when one user add or modify data locally, those changes are synced to other users when they become online. Is this possible with Firebase? Thanks!
Upvotes: 1
Views: 2199
Reputation: 1086
You need to use some events such as ValueEventListener or ChildEventListener to listener for the change of Data on Firebase, and Cast the data to the object.
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
YourPOJO changedData = dataSnapshot.getValue(YourPOJO.class);
//Do whatever you want here
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mPostReference.addValueEventListener(postListener);
You can use changedData object to refresh data of the views.
Upvotes: 1
Reputation: 345
just simply use the same reference/url (https://[FIREBASE_PROJECT_ID].firebaseio.com/) for all the users. thats it. visit this for a detailed example.
Upvotes: 0