0

This question is based on the firebase documentation here.

I am trying to implement Firebase Database in my app. What I'm trying to achieve is, I have a fairly huge database (~2MB) on firebase servers, which I don't want getting fetched everytime app fires a query.

I want to sync (new entries/edits) to the database only when the app starts. From that moment, in that session, whenever the app fires a query, it should get fired only on the offline database, even if active internet connection is available. I want to achieve this to make sure to use least internet data and gain maximum speed.

Is there any way (intended or a hack) to achieve this?

[Question edited]

Community
  • 1
  • 1
Srujan Barai
  • 2,295
  • 4
  • 29
  • 52
  • Duplicate http://stackoverflow.com/questions/40190234/firebase-what-is-the-difference-between-setpersistenceenabled-and-keepsynced – Frank van Puffelen Jan 20 '17 at 15:26
  • @FrankvanPuffelen hey Frank I saw your answers on many many Firebase related stackoverflow questions. Expected you to show up here and here you are. I read your answer on the link provided by you and that helped. I have mentioned a **specific scenario** in my question. If you can answer that, will be of great help :) – Srujan Barai Jan 20 '17 at 17:36
  • If you're asking about a specific scenario, please update the title to be about that (e.g. "how can I use Firebase's offline features to accomplish xyz?"). As it stands now, your question is a dupe of the one I linked, which explains exactly what the difference is. – Frank van Puffelen Jan 20 '17 at 18:11
  • Sure! I'll make all the changes in a moment. Frank! – Srujan Barai Jan 20 '17 at 18:16
  • @FrankvanPuffelen let me know if this is good for you to answer :) – Srujan Barai Jan 20 '17 at 18:41
  • If you want an offline database, I'd recommend using an offline database. Firebase's realtime database is not that: it is primarily an online database, that continues to work during short to medium term connectivity loss. – Frank van Puffelen Jan 20 '17 at 18:57
  • That said: you can probably do the sync once and call `goOffline()` after that. But in my opinion that is more trouble than it's worth: there are plenty of decent on-device alternatives if you only want to pull down data once and then read locally. – Frank van Puffelen Jan 20 '17 at 18:58
  • @FrankvanPuffelen Thanks Frank. One last question, just in case I go with this, can I know when my syncing is done so that I can go offline?anything like onSyncComplete – Srujan Barai Jan 20 '17 at 20:39
  • 1
    You can't. One of the many reasons I recommend not going with it. – Frank van Puffelen Jan 20 '17 at 20:40

0 Answers0