对使用同步适配器和内容提供程序同步多个表感到困惑
我很困惑哪种方式是在我的应用程序中同步多个表的最佳方式。
我有一个内容提供商,并打算拥有多个表(事件、用户等)。我还有一个应用程序应该与之通信的休息服务器。我想知道处理每个表的多个连接(放置、获取、发布和删除)的最佳实践是什么。他们也有关系,就像一个用户可以参加一个活动,但也可以成为该活动的所有者。因此,如果我创建了一个用户和该用户的所属事件,我可以上传该用户,从服务器获取有关该用户的信息,上传包含有关该用户的信息的事件,获取该信息,然后更新用户获得新的事件信息。
解决这些问题的最佳方法是什么?我应该创建一个方法(http://example.com/sync)来聚合所有应该同步的数据吗?或者我应该坚持,有时〜15-20个请求?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Evernote 通过其专有的 EDAM 协议解决了类似的问题。值得研究一下。
Evernote EDAM
Evernote has solved a similar problem with their proprietary EDAM protocol. Worth looking into.
Evernote EDAM
我建议您观看 Google I/O 2010 - Android REST 客户端应用程序视频。
这是对编写良好设计同步应用程序的一些概念和推荐模式的精彩介绍。
我个人找到了大部分问题的答案。
另请参阅此演示文稿。除了本演示文稿和随 SDK 提供的同步适配器示例之外,下面的列表应该为您提供充足的资料,让您能够相当快速地启动和运行同步适配器。
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.
这完全取决于您要同步的数据量。
如果只是文本数据,而且数量不多,您应该一次性同步所有数据。我建议将其全部编码为 json,压缩并将其发送到服务器(您将在其中解压缩、解析和保存)。 Json 是轻量级的,很容易在 android 上编写,并且可以在几乎任何类型的服务器上解析。
如果您想同步图像,最好一次同步一张,以确保在连接断开时保存部分进度。
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.