问题
My case is I connected to internet when login, then I turn off all connections and post some data (push + set). After that, I connect again but I see that new data is not sent to server.
How can I force data sync right after connection resumed
Note I used this from beginning:
Firebase.getDefaultConfig().setPersistenceEnabled(true);
Firebase ref = new Firebase(apiUrl);
ref.keepSynced(true);
回答1:
Firebase does this automatically. When a connection is lost, Firebase will continue to work offline firing events locally and working the the data persisted to the cache.
The local persistent cache has a size limit. When the cache hits the limit, the SDK will oust the least used data. Using .keepSynced()
is just a way to ensure the data isn't purged from the cache.
回答2:
This issue has same reason with Firebase-Android, Fail to save data after long time idle
Not really about "turn off all connections", let app idle for a long time then it happens.
来源:https://stackoverflow.com/questions/34259016/firebase-android-how-to-sync-data-when-resume-after-connection-lost