Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Offline Storage Advanced - Manual Sync and Progress Information

I have an App where a main Feature is "Offline Usage".

We generate a SQLite-Database on our Server what we provide on an API for download. Each time the Database has changed, the users had to redownload the Complete SQLite-Database (Which is currently 50MB and growing in time).

We tried to improve the Update-Method that the user only had to download the Difference-SQL files, but there are some problems (Performance, Corrupt Databases, etc).

Now Google Released Firebase and I thinks it's a good time to replace the SQLite-System with the Firebase System.

But I have some thoughts:

  • Can I download the entire Firebase Database for Offline Usage (Not in an App-Cache, in a persistent Storage)?
  • Can I track the Progress of the Offline Sync and give the User the option if he want's to sync now or later?
  • Can I restrict the Sync to WIFI only?
  • Can I deliver a Bundle Database - that after installing the App I can already query offline-Firebase Data?

What I want is: Using Firebase in my App only to sync the Databases - BUT perform all Operations offline. If Firebase is not designed to use this, what's a good alternative?

Then I've another main question regarding Firebase:

  • JSON Storage is great - but this way we don't care about a unique Structure, we must pay attention on this to insert always correct Datasets?
like image 325
brokedid Avatar asked Sep 20 '16 19:09

brokedid


People also ask

How does firebase offline sync work?

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.

Does firebase support offline mode?

Note: Offline persistence is supported only in Android, Apple, and web apps. To use offline persistence, you don't need to make any changes to the code that you use to access Cloud Firestore data.

Does Firestore cache data?

Firestore supports offline data persistence. This feature caches a copy of the Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.

What is the difference between firebase storage and Firebase Realtime Database?

Firebase Realtime database is stuctured as a JSON tree while Cloud Firestore stores data in documents (document is a set of key-value pairs) and collections (collections of documents). Realtime Database stores data in JSON tree while Cloud firestore stores data in documents which is very similar to JSON.


1 Answers

Can I download the entire Firebase Database for Offline Usage (Not in an App-Cache, in a persistent Storage)?

Yes you can do this by setting disk persistence to true. You just need to reference the highest level in the database and firebase will return all child nodes. https://firebase.google.com/docs/database/android/offline-capabilities

Can I track the Progress of the Offline Sync and give the User the option if he want's to sync now or later?

I have never tried to show the actual progress, however when you retrieve data from firebase there is always the onDataChange method that gets called when you have succesfully retrieved data. https://firebase.google.com/docs/database/android/retrieve-data#read_data_once

Can I restrict the Sync to WIFI only?

I have not seen this option in the Firebase documentation, however I do not believe it would be very difficult to implement

Can I deliver a Bundle Database - that after installing the App I can already query offline-Firebase Data?

You would need to grab data from Firebase as soon as the App is installed. You could also in theory when the app is first run try to write to the Firebase database without any network and then this data could be available locally, however you would need to be careful as when the user gets a network connection then this data might overwrite the data in the Firebase database. How do I cache Firebase data for offline usage?

like image 113
Riley MacDonald Avatar answered Sep 21 '22 01:09

Riley MacDonald