Firebase-Android, How to sync data when resume after connection lost?

a 夏天 提交于 2019-12-11 13:58:54

问题


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

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