How to synchronize Android database with SQL online server?

I am developing an Android application that stores various types of data in the embedded SQL Light provided by the Android platform.

Inside the application, I placed the “Sync” button, which should synchronize data between the local SQL Light database and the Online SQL Server database on my server.

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

Note. I do not want to centralize my database on the Internet, because I also want to give mobile users the opportunity to use the application without an Internet connection.

Thank.

+45
android synchronization sql sync
Jul 02 '12 at 18:31
source share
1 answer

You should see the SampleSyncAdapter project in the Android SDK demos ( Transferring Data Using Sync Adapters ). It shows you how to sync “Android style”, which does not require user interaction by constantly pressing the sync button.

In addition, you need to write server software that can provide your SyncAdapter with a “delta” of all changes since the last commit. The easiest approach is to save the "last synchronized" timestamp in your application, which should come from the server, otherwise you may get into the problem due to the time difference between the client and server. Normalize all timestamps as GMT or any time zone of your choice, but stick to this solution. If your application needs to display a timestamp in local time, you need to use Java Calendar and TimeZone to convert the normalized timestamp to local time.

In addition, your application should also mark the changed local records as dirty, so your SyncAdapter knows that it needs to upload these changed or new records to the server.

The following minimum functions are required for your server software:

  • Update existing recording function.
  • Add new function entry
  • Get updated records since the last synchronization (the application provides a timestamp)
  • Get new records since the last synchronization (the application provides a timestamp)

You can also read some Google APIs (e.g. Google Calendar) to get an idea of ​​how it all works and how to create a server API for communication.

+57
Jul 02 2018-12-12T00:
source share



All Articles