15

I'm confused about which way is the best to have multiple tables get synced in my application.

I have one content provider and intend to have multiple tables (events, users, etc). I also have a rest-server that the app is supposed to communicate with. I'm wondering about what is the best practice to handle multiple connections (put, get, post and delete) for each of the tables. They have also relationships, like one user can be attending an event, but also be the owner of the event. So if I have created a user and a belonging event to that user, I can either upload the user, get back info from the server about the user, upload the event with the information about the user, get back that information and then update the user with the new event information.

What is the best way to solve these problems? Should I create a method (http://example.com/sync) that aggregates all the data that should be synced? Or should I just stick with, sometimes ~15-20 requests?

jonepatr
  • 7,769
  • 7
  • 30
  • 53
  • [This may be of help](http://stackoverflow.com/questions/3814005/best-practices-for-exposing-multiple-tables-using-content-providers-in-android) – Reno Oct 27 '11 at 02:53
  • That doesn't answer my question exactly. The link you shared (thanks) is about exposing your content provider tp the rest of the android system, internally. My question is more about syncing your data externally, and how to make the most efficient connection to the server to transmit/receive data. – jonepatr Oct 27 '11 at 09:35
  • Yeah I know that, sorry I haven't worked with SyncAdapters at all, I'll upvote your question. – Reno Oct 27 '11 at 09:43

3 Answers3

7

Evernote has solved a similar problem with their proprietary EDAM protocol. Worth looking into.

Evernote EDAM

R.daneel.olivaw
  • 2,681
  • 21
  • 31
Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
6

I would recommend you to watch Google I/O 2010 - Android REST client applications video. It’s a fantastic introduction into some of the concepts and recommended patterns for writing well design syncing applications.

I personally found answers to most of my questions.

Also look this presentation. Along with this presentation and the sync adapter sample provided with the SDK, the following list should provide you ample ammunition to get a sync adapter up and running fairly quickly.

Huds0nHawk
  • 1,486
  • 16
  • 26
2

It all depends on the amounts of data you want to sync.

If it's only text data, and not a lot, you should sync it all at once. I would recommend encoding it all to json, zipping it and sending it to the server (where you would unzip, parse and save). Json is lightweight and easy to compose on androi, as well as to parse on almost any kind of server.

If you want to sync images, you'd be better off syncing them one at a time, to be sure you have partial progress saved in case the connection drops.

zrgiu
  • 6,200
  • 1
  • 33
  • 35