1

I am developing an android application which have

  • SQLite on the mobile
  • MS SQL on the Windows server

I want the mobile data to sync with the MSSQL database whenever a new entry is added. The sync data should remain in the mobile and work even if the mobile internet is offline.

The MSSQL database will have two identical (same fields structure and fields name)

I need to develop synchronization between these DB in one way.

The mobile application doesn't have any options for editing.

If I change data from server then it should change data in android

Sync will run the first time the application is started plus I will like to provide a sync button.

How do I sync databases in Android?

I have found several things but I am at beginners level. I didn't find any samples. I tried the "http://programmerguru.com/android-tutorial/how-to-sync-remote-mysql-db-to-sqlite-on-android/" tutorial but it uses php and MSSQL.

I will appreciate if some one will give me some sample code with some explanation or something like that which will show me a way to do this.

Danish_k12
  • 329
  • 2
  • 3
  • 20

1 Answers1

1

First you need to write a sever side code which read the data from (MySQL database) and send it to mobile app, then you receive this data and add save (or update) it in(SQLite database). To inform the application about the new data you can make a global variable saved on the server (or create a new table to add this value). this value will be increased each time MySQL database updates its tables. And each user app will request to get this variable and compare it with the last one each time he start the application.

  • if equal => no change => continue with old SQLite database.
  • if grater => update SQLite database.

Or another way is to use GCM: 'Google Cloud Messaging" to send a message to all user telling them to download and sync the database, but this way needs a new database table on server side (MySQL database) to store user's id and their GCM Token.