您能否向我解释如何实现同步到我的应用程序的逻辑? 我的意思是,我有同步代码,我有服务,提供商,一切,但我不明白(我有Android编程(OReilly)教程的同步代码)。
所以,我想,同步应该是这样的:
......到目前为止,非常好。我的帐户显示在“帐户/同步”
中我假设我应该将令牌存储在服务器端(也许在“users”远程表中) 然后我想,我应该实现我的同步逻辑。现在这是我的问题: 同步逻辑应该是这样的吗?
远程table1结构: 的ID,姓名,出生日期,缺失
远程table2结构: id,invoice_no,invoice_date,invoice_total,已删除
本地(SQLite)tablex1结构: _id,姓名,出生日期,缺失
本地(SQLite)tablex2结构: _id,invoice_no,invoice_date,invoice_total,已删除
我应该在本地表中添加一个像“remote_id”(整数)这样的新字段吗?
然后在远程表中添加一个名为“synced”(boolean)的新字段,或者可能是“synced-timestamp”?
然后有两种方法: pull() (用于从远程获取数据)和 push() (用于将数据发送到远程)
onPerformSync我应该进行如下验证:
(推送)
- send to remote a list with all records from tablex1 and tablex2 that have "remote_id" = null
- on the server side, the PHP (after checking the token to be valid) will insert the new rows, with "synced" set to true
(拉)
- ask the remote to send back to me the list of all records that have the synced=false, then set them to true on remote.
- process the returned rows and insert them locally in SQLite (including "remote_id")
这是一个好方法吗?是否容易出现重复或其他问题?我应该用什么作为逻辑呢?
你做什么同步?
你推荐什么逻辑?
谢谢