For example, you want to sync table todoTable
from MySql
to Sqlite
First, create one column name version (type INT)
in todoTable
for both Sqlite
and MySql
Second, create a table name database_version
with one column name currentVersion(INT)
In MySql
, when you add a new item to todoTable
or update item, you must upgrade the version of this item by +1 and also upgrade the currentVersion
In Android
, when you want to sync (by manual press sync button or a service run with period time):
You will send the request with the Sqlite
currentVersion (currently it is 1) to server.
Then in server, you find what item in MySql
have version value greater than Sqlite
currentVersion(1) then response to Android (in this example the item 3 with version 2 will response to Android)
In SQLite
, you will add or update new item to todoTable
and upgrade the currentVersion