Keep Android local DB (Realm) in sync with SQL Server with minimal network overhead

杀马特。学长 韩版系。学妹 提交于 2019-12-25 06:23:53

问题


The Situation

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.

The Caveat

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. Call a service in the onPause() of the current activity to run after the fact? Is this guaranteed?

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

  3. 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!


回答1:


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



来源:https://stackoverflow.com/questions/37686619/keep-android-local-db-realm-in-sync-with-sql-server-with-minimal-network-overh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!