1

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);
Ricky
  • 569
  • 4
  • 16

2 Answers2

0

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.

David East
  • 31,526
  • 6
  • 67
  • 82
  • Thank for your reply, but I waited for a long time but still don't see any new data send to database. – Ricky Dec 14 '15 at 03:01
  • Can you detail step-by-step, what you're doing and what you're seeing? Because Firebase resyncs when the device regains its connection. – David East Dec 14 '15 at 03:04
  • It randomly happens. I try as following step: 1. Login (connect internet) 2. Turn off connection 3. Call push + set to add new data 4. Turn on connection and wait. I try 10 times, and lost 2 of them – Ricky Dec 14 '15 at 03:23
  • Do you have any security rules written? – David East Dec 14 '15 at 03:31
  • Yes. This is my rules in short https://gist.github.com/rickyngk/bee4dccfc655570e991d – Ricky Dec 14 '15 at 03:45
  • Or you can also take a look at whole my project here https://github.com/rickyngk/pal (included full version of bolt file) – Ricky Dec 14 '15 at 03:46
  • Note that it happens randomly with low probability. I run beta test in last week, and there's one user report. I myself reproduce on my device, it got 2 this morning. But then dont happen anymore up to now – Ricky Dec 14 '15 at 03:49
  • 1
    It sounds like a network issue, but it's impossible to tell. You'll probably get some more insight if you run Firebase with debug logging, by calling `Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG)` before creating any Firebase reference. – Frank van Puffelen Dec 14 '15 at 04:58
  • Yep, I'll report more detail when I get it. – Ricky Dec 14 '15 at 05:31
  • Hmm. It happens again and this is log https://gist.github.com/rickyngk/b0e5c4216816fef89649 I try to save data to /posts/$key 4 times but lost all – Ricky Dec 14 '15 at 06:03
  • A note: It happens when I minimize application and leave it inactive in some hours, then I resume it from recent app list. – Ricky Dec 14 '15 at 06:14
  • Did you get a solution? I'm going through this situation .. it's terrible, user losing all the work! – Jonas Rotilli Dec 04 '17 at 19:26
0

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.

Community
  • 1
  • 1
Ricky
  • 569
  • 4
  • 16