使用远程 API 同步 Android 应用程序数据库的策略 [英] strategy for syncing Android app database with a remote API

查看:29
本文介绍了使用远程 API 同步 Android 应用程序数据库的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android 应用程序,它是远程 JSON 网络服务 API 的客户端(我构建了服务器,因此我拥有最大的灵活性).

I'm developing an Android app that is a client to a remote JSON webservice API (I built the server so I have maximum flexibility).

我正在尝试确定什么是使本地 SQLite 数据库与远程 API 同步的好策略(在电池寿命、带宽和等待时间方面).

I'm trying to decide what is a good strategy (in terms of battery life, bandwidth and wait times) to keep a local SQLite database synced with the remote API.

我目前的想法是,服务器将通过 GCM 通知 Android 应用有关任何操作(应获取的新数据或应更新的旧数据),此外,用户将有一个刷新按钮来手动进行同步.

what I'm currently thinking is that the server will notify the Android app via GCM about any action (either new data that should be fetched or old data that should be updated), also, the user will have a refresh button to manually do the sync.

这种方法的缺点是,如果 GCM 消息丢失",则无法知道任何更新或新数据.

cons of this approach is that if the GCM message is "lost" there is no way to know about any updates or new data.

我可以在用户要求查看某些内容时添加时间戳并检查新数据,但这并不能解决确定何时需要刷新 SQLite 数据库中已有的旧数据的方法.

I can add timestamps and check for new data whenever the user asks to view something but this doesn't solve the way to determine when older data that's already in the SQLite database need to be refreshed.

关于改进这种同步策略的任何建议或我应该研究的任何其他方法?

any suggestions for improving this syncing strategy or any other approaches I should look into ?

推荐答案

您可以让应用在收到 GCM 推送时向服务器发送收到的确认.然后,如果服务器在 X 时间范围内没有看到确认,它可以重新发送 GCM 推送.

You could have the app send a received acknowledgement to the server when it gets the GCM push. Then, if the server doesn't see an acknowledgement in X timeframe, it could resend the GCM push.

这篇关于使用远程 API 同步 Android 应用程序数据库的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆