0

In Firebase I wanted to ask about usage for the setPersistenceEnabled(true).

When I was running tests involving removing entries like this:

"ADDRESS_ID" : {
      "US(fss)district of columbia(fss)washington(fss)pennsylvania ave se(fss)1600" : {
        "-KZhVUg43lazrLQbIuLJ" : "true"
      },
      "US(fss)district of columbia(fss)washington(fss)pennsylvania ave se(fss)1601" : {
        "-KZs0G5-FP3QW3MeoWre" : "true"
      },
}

Just to see what my Firebase Query would return. When I removed one of the above like the: ..se(fss)1601 Then my search query looking like this still return both keys in the above code.

Query query = databaseRef
        .child("TOYS
        .concat("/"
        .concat("ADDRESS_ID")
        .concat("/"))
        .orderByKey()
        .startAt(US(fss)district of columbia(fss)washington(fss)pennsylvania ave se(fss));
        query.addListenerForSingleValueEvent(singleShotListener);

I waited ten minutes and run the above Query again and the dataSnapshot.getChildrenCount() was =2 and I see that both keys is the above.

When I after half en hour clear app cache and data on my target device Galaxy Note 4 and of course deleted the SQLite database used by Firebase Database?, then my Query only return the "existing" key ..nw(fss)1600

I suppose this could be expected behavior or?

Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
  • 1
    This is indeed expected behavior. But is has nothing to do with the time you wait and solely with the number of times you run. In general `addListenerForSingleValueEvent` and `setPersistenceEnabled(true)` don't work well together. See my answer here: http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent – Frank van Puffelen Jan 17 '17 at 14:50
  • ok added ´query.keepSynced(true);´ before the ´query.addListenerForSingleValueEvent(singleShotListener);´ Of course I can use the ´addValueEventListener´ but then I must remove the listener and it feels like it´s not the right way since I really need to get one key once – Tord Larsen Jan 17 '17 at 17:06
  • If you just *added* `keepSynced(true)`, you've just *added* to your problem. If you didn't have `keepSynced(true)` before, the problem must be coming from somewhere else: remove `keepSynced(true)`, uninstall and reinstall the app. – Frank van Puffelen Jan 17 '17 at 17:29
  • But I have the ´setPersistenceEnabled(true)´ right and you [say](http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent) that - "As a workaround you can also call keepSynced(true) on the locations where you use a single-value event listener. This ensures that the data is updated whenever it changes, which drastically improves the chance that your single-value event listener will see the current value.". I didn't have keepSynced(true) before, Thanks what am i missing? – Tord Larsen Jan 17 '17 at 18:34
  • Ah right. I keep mixing up `keepSynced()` and `setPersistenceEnabled()` in my mind. It's hard to understand exactly what goes on without a [minimal, complete verifiable example that reproduces the problem](http://stackoverflow.com/help/mcve). But as I said: the best solution is to not mix disk persistence and single value listeners. – Frank van Puffelen Jan 17 '17 at 21:08
  • thanks for all your great fast answers always – Tord Larsen Jan 17 '17 at 21:45

0 Answers0