问题
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.
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?
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