MySql数据库服务器上的数据更改时如何在Android应用程序中同步SQLite数据库

问题描述:

在我的应用程序中,我必须使用REST API在应用程序中的服务器和SQLite DB之间同步数据.
我有一项类似待办事项的活动,在该活动中,服务器上的所有待办事项将通过向应用程序的推送通知进行通知.现在,让我们检查senario.

In my app, I have to consume REST API for syncing data between server and SQLite DB in app.
I have one activity like To-Do's in which all the To-Do's post on server will notify by the push notification to app. Now, lets check senario.

服务器上有3个待办事项

-注1
-注释2
-注释3

There are 3 To Do 's on server

- Note 1
- Note 2
- Note 3

该服务器上有三个待办事项,所有这些都已同步并存储在应用程序的SQLite中.当用户打开应用程序时,通过使用存储在SharedPrefs中的时间戳请求新的注释,只有新的注释在应用程序中同步.但是,如果-Note 2在服务器(MySql DB)上的更改比

-如何以最少的N/W调用同步应用程序中已更新或已删除的注释.
-我们可以触发推送通知吗? (静默地)通知应用程序服务器上的数据已更改,因此可以在应用程序下次启动时进行同步.

我已经搜索了这个问题,但是找不到合适的解决方案.

There are three To Do's on ther server and all of them are synced and stored in SQLite in the app. And only new notes are synced in the app by requesting for new notes using timestamp stored in SharedPrefs when user opens the app. But, what if -Note 2 is altered on server(MySql DB) than,

- How to sync the updated or deleted notes in app with minimum N/W calls.
- Can we fire push notifs(silently) to inform the app there is altered data on server, so it can be synced on next startup of the app.

I have search for this problem but cannot find appropriate solution.

android中有一个很好的主题

There is very Good Topic in android Sync Adapter. Its worth giving it a try. See the reference link from Android Developer website