0

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • You can prepare a json file and import it. You can use json when offline to synchronize when online. You can look over here. I hope it helps. http://stackoverflow.com/questions/36395552/saving-json-object-to-firebase-in-android – mesutpiskin Feb 13 '17 at 07:51
  • Quick answer below. But it'll be hard to say more without knowing more about the problem. As it stands, your post reads like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem).Consider sharing the [minimal, complete code that reproduces the problem](http://stackoverflow.com/help/mcve) for better answers. – Frank van Puffelen Feb 13 '17 at 14:55

2 Answers2

0

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.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807