So for my Android App which stores data of workouts I have been using a SQLite Database so far. Now I want to implement these features:
Offer workouts in real time (with Firebase Database)
Being able to access your data on other devices and maybe from an web app
later
I figured, that for this purpose Firebase would be a great fit. But switching from SQLite to Firebase would bring a few down sights in my opinion:
Every user would need to sign up. I think for some users this is a reason to
not use my app. There is no way to avoid having to sign up when using
Firebase to store the data for user, right?
I´m not sure how good the offline options of Firebase Database is. How long
will the data be accessible without a connection? Is the capacity and
performance comparable to a SQLite Database?
I thought an alternative way could be to use Firebase just for offering the workouts but keep the data about a workout (repetitions, weight, ...) in a SQLite Database. Then I could upload the Database File with Firebase and another Device could download and continue it. Could that be an option?
Any thoughts and advice are appreciated!
Every user would need to sign up. I think for some users this is a
reason to not use my app. There is no way to avoid having to sign up
when using Firebase to store the data for user, right?
Right. (Technically it is possible, however you will need to enable read / write operations to non registered uses which is a no-no and not recommended at all.)
I´m not sure how good the offline options of Firebase Database is. How
long will the data be accessible without a connection? Is the capacity
and performance comparable to a SQLite Database?
From the firebase database docs: Firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored..
So yes, you can continue writing to it even when offline and read the already cached data, but this does not solve your concern that users will have to register to use the app.
Possible solution
Use both SQLite and Firebase database:
For a registered user, always write in both SQLite and Firebase to keep them in sync (write in Firebase first and then SQLite). Another option is to write in SQLite and sync to Firebase every X minutes. Read data from Firebase when online and from SQLite when offline.
When the user is offline, you will to write data to SQLite. You will need to mark those records as non-synced so that next time it is connected you will write them to firebase.
Also, when reconnected, you'll need to somehow merge firebase data (that might have changed) and local SQLite data. The algorithm for this depends on your app.
For non-registered users, use SQLite only.
The downside to all this is that the complexity of your application increases a lot. It's up to you to decide whether it's worth it or not. :)
Related
I am building an app for a gym which shows gym members info in a recyclerview at the app startup , the problem is at every fresh launch of the app the data is pulled from the firebase database and appears suddenly after 4-5 seconds in the recyclerview after the app starts, and i think this time will increase as the data grows.
If the data is same why pull it every time.
But i want to go one step further
what i want is when the user logs in for the first time all the data liked to that account should get pulled off and stored locally , i don't want to pull the data ever again even if the user is connected to internet, the changes user make should be made to realtime database as well as locally regardless how much data is created , so that i never need to pull data again once the user is logged in but just push the data every time it changes or grows or gets deleted, operations will happen to both local storage as well as at realtime database, so the user will always have local access to data he created.
And if he logs in again same thing happen again.
Is there a way to do it with firebase without implementing local sqlite database together with firebase realtime database.
This answer is for a use case where data is stored locally as well as on a remote server - similar to what's in the question. It may not specifically answer the question but may lead to a solution.
In the question, it appears there's local data and remotely stored data which are essentially the same - the OP is using sql to store locally and Firebase to store remotely. This is being done to 'speed up' the loading process and lower the amount of reads.
My suggestion is to use Firebase only. It's very fast and if coded correctly, the loading time should never be 4-5 seconds before the UI is available to the user (barring a bad internet connection if not using persistence).
Additionally, Firebase offers locally persisted data in two ways; cached data and persisted data (which are similar but read on)
Cached: Firebase apps automatically handle temporary network interruptions.
Cached data is available while offline and Firebase resends any writes
when network connectivity is restored.
and
Persisted: 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. Listener callbacks will continue to fire for local
updates.
There's a lot more to it so please see iOS Offline Persistence and Enabling Offline Capabilities on Android
Your questions suggests that the Firebase SDKs provides this sort of functionality. It does not. You will have to implement something yourself.
The best way to tackle this in an easy and the most efficient way is to use the Room Persistence provided by AndroidX Architecture.
It is technically an ORM over SQLite. Please find the details here:
AndroidX Room Persistence
I'll like to know if it is possible to increase the size of the local cache of the firebase firestore database?
Will also like to deepen my knowledge on how firebase firestore offline
data persistence functions on mobile( android specifically).
Let me explain my use case and you evaluate if firebase firestore is the route to go for me.
I require a local database that can be synced averagely after every 24 hours and I require it to function offline and persists it's data. The main use case is this: I have a messaging feature integrated into the application and just as everyone expects to see his messages he's got to send and receive before he was disconnected that is, just as even when one is disconnected, he still can see his different conversations on whatsapp even after a phone reboot, that's how i expect my application to follow and I want to know if firebase firestore local cache offers me this possibility of persisting the cache even after phone reboot without having to connect to the internet? I do expect a lot of reads from the local cache but not that of writes while offline.
To summarize my question, can the local cache persists changes that have been made while the phone was offline even after phone reboots without any connection to the internet? Thank you all for your answers and time taken to read this in advance.
Please, do include some helpful links to tutorials showing how to use it if you do know any of them.
The size of the local cache depends on the size of the storage of your device. If you want to increase the size of your local storage, then you just need to free some space or buy a new hardware. There is no limitation regarding the maximum size that can be stored on your device.
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud 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. So, Cloud Firestore persists the data you write on a device to a local database. So the next time you start the application, it will indeed be able to read that same data, even when the device has never been connected to the Firebase servers. And as an answer to your question, yes it can.
But don't use Cloud Firestore as an offline-only database. It is really designed as an online database that came work for short to intermediate periods of being disconnected. While offline it will keep a queue of all your write operations. As this queue grows, local operations and app startup will slow down.
Nothing major, but over time these may add up. But remember, all these operation will persist even if you restart the device. You not gonna lose any data.
I am trying to develop an app whereby I want to exchange files (video, images) within the cloud storage(firebase) and client(android app).
I wanted to know if there is any sync API in firebase which keeps track of any updates i.e any changes being performed in the firebase storage and replicating the same to the client (and vice-versa if possible).
Thanks in advance !!
Go to the page of Firebase and read what the header says:
Store and sync data in real time
Furthermore:
The Firebase Realtime Database is a cloud-hosted NoSQL database that
lets you store and sync data between your users in real-time.
What Realtime means is this:
Instead of typical HTTP requests, the Firebase Realtime Database uses
data synchronization—every time data changes, any connected device
receives that update within milliseconds. Provide collaborative and
immersive experiences without thinking about networking code.
So just add Realtime Database Dependency and you are set. This itself will serve the purpose of Sync API you need.
I have been using SQLite as my storage solution for my android applications. I want to be able add synchronization functionality to one of my apps, Firebase looks like a good solution but the problem is that I need to know if I am to use Firebase to sync data with the SQLite database or Firebase can work and totally replace SQLite. I know Firebase has offline persistence but while offline can it hold as much data as SQLite and are the queries as powerful?
Clearly this depends on the business rules for which the options are considered. So there will not be the "right" answer to this.
At least one of our team members was thinking along these lines. Here is our solution:
Do all transactional data locally on the SQLite as we do not need transactions to be across devices.
Sync the rest using Firebase.
(1) makes sure that we don't misuse Firebase's non-persistent offline availability of its client.
The docs
Even with persistence enabled, transactions are not persisted across app restarts. So you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your app should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your app remembers them manually and executes them again after an app restart.
(2) make sure that we use Firebase's persistent offline nature to synch non-transactional data across devices once connection is (re)established.
The docs, The Firebase Realtime Database client automatically keeps a queue of all write operations that are performed while your app is offline. When persistence is enabled, this queue is also persisted to disk so all of your writes are available when the user or operating system restarts the app. When the app regains connectivity, all of the operations are sent to the Firebase Realtime Database server.
This way we achieve a state acceptable within our use.
"can it hold as much data as SQLite and are the queries as powerful?" no and no if powerful is translated as "transaction across devices", by definition of Firebase being a remote database.
I am developing an android app with Google Maps.
Basically what a I want to do is to store the location where the user clicks in a database, but I want to store this information for all users that have the app.
I already read about SQLite in Android and his stuff but seems like I only can create a local file where I can store information. I want this information to be sync everytime the app is opened. I don't know how neither where store this information online.
Do I need something like Google Cloud SQL or any other database server to achieve this?
Thanks for all.
UPDATE 09/10:54
I recently discover that MongoLab gives you a simple database to use. In every sample I see for Content Providers in Android or Sync Adapters, I never saw a single database call nor declaration anywhere.
How you can link a content provider or sync adapter to a database?
UPDATE 09/11:24
In the Xamarin docs you can learn how to create a custom Content Provider, but again ... no database is included or mentioned.
Take a look at Sync Adapters:
Synchronizing data between an Android device and web servers can make your application significantly more useful and compelling for your users. For example, transferring data to a web server makes a useful backup, and transferring data from a server makes it available to the user even when the device is offline. In some cases, users may find it easier to enter and edit their data in a web interface and then have that data available on their device, or they may want to collect data over time and then upload it to a central storage area.