如何Android的数据库与网上的SQL Server同步? [英] How to Synchronize Android Database with an online SQL Server?

查看:325
本文介绍了如何Android的数据库与网上的SQL Server同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序存储不同类型数据的内置的Andr​​oid平台提供的SQL光。

I am developing an Android App that stores different types of data in the built-in SQL Light provided by the Android Platform.

里面的应用程序我已经把一个同步按钮,这是应该同步本地SQL轻型数据库之间的数据,有一个在线的SQL Server数据库在我的服务器上。

Inside the App I have placed a "Sync" button which is supposed to Sync the data between the local SQL Light Database, with an Online SQL Server database on my server.

解决办法来处理呢?该功能可以在谷歌日历,在这里你可以查看你的手机上的日历事件,当你添加一个新的事件,并同步数据,您可以将您的网上帐户也查看更新的数据中找到。

What is the workaround to handle this? This feature can be found in Google Calendar, where you can view the calendar's events on your mobile, and when you add a new event and Sync the data, you can view the updated data by going to your online account too.

注:我不希望我的集中数据库联机,因为我也想给移动用户使用的应用程序没有互联网连接的能力。

Note: I don't want to centralize my database online, because I also want to give the mobile users the ability to use the App without internet connection.

感谢。

推荐答案

您应该看一看在Android SDK中演示的SampleSyncAdapter项目(的传输数据使用同步适配器)。 它表明你如何做同步机器人式,而无需用户交互通过手动攻丝的同步按钮,所有的时间。

You should take a look at the SampleSyncAdapter project in the Android SDK demos (Transferring Data Using Sync Adapters). It shows you how to do synchronization "Android style", which requires no user interaction by manually tapping a sync button all the time.

在的,你需要编写服务器软件,能够提供你SyncAdapter所有更改的增量自从上次提交顶部。最基本的方法是保持上次同步时间在你的应用程序,其中有来自服务器的印章,否则,你可以得到的,因为客户端和服务器之间的时间差陷入困境。规范化所有时间标记为GMT或您选择的任何时区,但坚持这一决定。 如果你的应用程序需要在本地时间显示时间戳,那么你需要使用Java日历和TimeZone类用于将归一化的时间戳到本地时间。

On top of that you need to write server software that is able to provide your SyncAdapter with a "delta" of all changes since the last commit. The most basic approach is keeping a "last synchronized" time stamp in your app which has to come from the server, otherwise you could get into trouble because of time differences between client and server. Normalize all time stamps as GMT or any timezone of your choice, but stick with that decision. If your app needs to display a time stamp in local time, then you need to use the Java Calendar and TimeZone class for converting the normalized time stamp into local time.

您的应用程序也需要改旗方志为脏,所以你的SyncAdapter知道它需要这些改变或新记录上传到服务器。

Your app also needs to flag changed local records as "dirty", so your SyncAdapter knows that it needs to upload these changed or new records to the server.

以下最低功能所需的服务器软件:

Following minimum features are needed for your server software:

  • 在更新现有的记录(S)功能
  • 添加新的记录(S)功能
  • 在获取更新的记录自上次同步(应用程序提供时间戳)
  • 在获取新记录自上次同步(应用程序提供时间戳)

您可能还需要阅读一些谷歌的API(如谷歌日历)获取如何这一切工作,以及如何设计服务器API接口进行通信的想法。

You also may want to read through some Google API (like Google Calendar) for getting an idea of how all of this works and how to design the server API interface for the communication.

这篇关于如何Android的数据库与网上的SQL Server同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆