保持Android本地数据库(Realm)与SQL Server同步,以最小的网络开销 [英] Keep Android local DB (Realm) in sync with SQL Server with minimal network overhead

查看:124
本文介绍了保持Android本地数据库(Realm)与SQL Server同步,以最小的网络开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

一段时间以来,我一直在努力奋斗.我有一个使用Realm和后端SQL Server DB的本地数据库.我的应用程序中有一些区域可以非常快速地更改数据(例如,一个复选框).用户每秒可以多次来回切换数据.因此,可以说用户在一秒钟内进行了10次更改.我要避免的是在那一秒内将其发布到SQL Server 10次.相反,我想发生的事情是有某种批处理过程,每5到10秒执行一次以同步数据,从而减少了网络调用.

I've been banging my head on this one for awhile. I have a local DB using Realm with a back end SQL Server DB. There are a few areas in my app where data can be changed very quickly (a checkbox for instance). The user has the ability to toggle data back and forth many times a second. So lets say the user in the matter of a second makes 10 changes. What I am trying to avoid is POSTing out to SQL Server 10 times in that second. Instead what I'd like to happen is have some sort of batch process that executes every 5~10 seconds to sync up the data thus reducing network calls.

警告

即使用户在5〜10秒标记之前或执行POST调用时杀死了该应用程序,我如何确保同步过程也会触发.

How can I ensure the sync process will fire even if the user kills the app before the 5~10 second mark or while the POST call is being executed.

  1. 在当前活动的onPause()中调用服务以在事实发生后运行吗?这是 保证吗?

  1. Call a service in the onPause() of the current activity to run after the fact? Is this guaranteed?

是否缓存数据并在下次启动应用程序时重试?

Cache the data and try again on the next app launch?

使用GCM或某种形式的推送服务来启动预定的同步吗?

Use GCM or some form of push service to initiate a scheduled sync?

我知道这没有灵丹妙药,但是如果有人遇到类似的问题,请多加建议和最好的做法,在此先感谢您!

I understand there is not a silver bullet for this but if anyone has ran into a similar concern any suggestions/best practices are appreciated, thanks in advance!

推荐答案

尝试在领域中使用onchangesListener.将更新后的数据或新数据同步到sql server.

try to used onchangesListener on realm. to sync your updated or new data to sql server..

这篇关于保持Android本地数据库(Realm)与SQL Server同步,以最小的网络开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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