How to Synchronize Android Database with an online SQL Server?

前端 未结 1 1028
你的背包
你的背包 2021-01-29 20:25

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

Inside the App I have placed a \"Sync\" butto

相关标签:
1条回答
  • 2021-01-29 20:44

    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.

    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.

    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:

    • Update existing record(s) function
    • Add new record(s) function
    • Get updated records since last synchronization (app provides time stamp)
    • Get new records since last synchronization (app provides time stamp)

    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.

    0 讨论(0)
提交回复
热议问题