user6354
user6354

Reputation: 135

Share same Firebase db with multiple users

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

Answers (2)

Seanghay
Seanghay

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

Simo
Simo

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

Related Questions