When syncing offline data on Firebase, new online data from other devices will be removed. I need to sync my offline data and keep new online data without removing. Is it possible?
Thanks for answers.
When syncing offline data on Firebase, new online data from other devices will be removed. I need to sync my offline data and keep new online data without removing. Is it possible?
Thanks for answers.
You can distingish your Firebase users by their uids. User uid is available through FirebaseAuth.getIntance().getCurrentUser().getUid();
You can put the uid in the root of you user's JSON data.
This way you can keep/update whatever you need on by-user basis.
If you have multiple users writing to the same location, then indeed the last write will win and others will be overwritten. For this reason, you should prevent users from writing to the exact same location.
Firebase push IDs are designed to precisely do that: they are generated on the client, but statistically guaranteed to be unique. So by calling push()
you can ensure that all clients write to a unique location.