I am using Firebase realtime database in my Android application. I have replica of database in local device using below line of code -
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
But it will sync all the tables between local and global database. I only want few table need to be sync not all.
Is there any way to only sync few tables in local memory and rest of table Android device will read from global database?
When you are using the following line of code:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
All the data that the user recently received is cached to disk.
Is there any way to only sync a few tables in local memory and the rest of the table android device will read from the global database?
No, there is not! There is no way to exclude certain nodes from that disk persistence. Unfortunately, you cannot choose whether a node should be or shouldn't be cached on the disk. It's all or nothing.
Related
I am looking for guidance in a proper way to use Firebase's Storage in order to synchronize some CSV files copies of which are stored in raw on the local device. I'm fairly new to Firebase storage.
Essentially, I wish to be able to push any changes made to the Firebase Bucket onto the local device. So anytime a CSV file is updated, a new one is added, or one is removed, I wish that to be synchronized with the copies stored on the device. Using the realtime database to store these CSV files in JSON is not an option for various reasons. It might also be worth mentioning that any file changes will be made by hand on the Firebase terminal.
I'm aware that Firebase allows us to list all the files contained at a reference point by calling .listAll() on a storage reference. However, I cannot find any documentation on this function or how to detect and update file changes.
Any help you can give me would be appreciated.
Cloud Storage for Firebase does not offer any APIs for automatically synchronizing objects in storage buckets between the client and server. It doesn't work at all like Realtime Database.
If you want to implement this, you will need to write a lot of code to implement that synchronization on your own. It won't be easy. You can take advantage of the sync provided by Realtime Database to reference which content might be new (if you store dates and paths to Storage), but ultimately, you will have to download and delete files manually as needed to make sure the client is up to date.
I'm using 4 RecycleView in MainActivity which load data from Cloud Firestor using FirestoreRecyclerAdapter. Now I want to use Room to create receipt for the user in ReceiptActivity.
I did all staff, but there is something wrong when I try to delete and update item in Room. My app is crashing, so I'm asking if there is conflict with what I'm doing or not? If not,please guide me with best practice to do that. Thanks in advance.
Error message
When using Cloud Firestore, offline persistence:
For Android and iOS, offline persistence is enabled by default. To disable persistence, set the PersistenceEnabled option to false.
Which means that Firestore will create a local (internal) copy of your entire database on users device. So the same thing that you want to get can be also achieved without adding an extra local database because by default is one that already exists.
Furthermore, if you need to get the data from the cache only, you can achieve this with the help of the DocumentReference.get(Source source) and Query.get(Source source) methods.
By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the Source parameter.
So we can now pass as an argument to the DocumentReference or to the Query the source so we can force the retrieval of data from the server only, chache only or attempt server and fall back to the cache.
I use Parse.com for storing my data but since they will shut down their service I am going to use Backendless in the future.
I use it in my Android app for syncing my data between devices. Since the app can work offline I will use a SQLite DB to store the data and sync it to Backendless when online. And new data from Backendless will be stored in the SQLite DB as well to be available when working offline.
So when offline and creating a new record, I have to store it in SQLite until being online again. Now can I set the ObjectId, which is the identifier of Backendless objects, manually and will Backendless still get that is has not been saved to the cloud even already having an ObjectId set?
Even if the backend accepts an external objectId (and I think it doesn't), it's safer to just drop the local ObjectId before sending the objects to the backend, and let the backend generate a new one. This way, you won't have to manage several ID generators and worry about unicity.
If you can't change the local ObjectId, you can still delete and re-create the local object with the backend Id.
I use the Parse.com Cloud service in my Android app to sync data between devices.
I use the app mainly offline and use the local DB
Parse.enableLocalDatastore(getApplicationContext());
I want to deploy my app with a local DB that already contains a few thousand records. How can I do that? I don't want to sync the data on every device on first use.
Local datastore is not really a "local db", although you get some of the benefits a local db would give you. There is unfortunately no way to pre-populate the local datastore like you're after. The only way I can think of is to use another technology (like sqlite/core data etc) to store the pre-populated data. The problem is that to pin the data to the local datastore, you would need to get the PFObjects from Parse first anyway...
The Parse local datastore is not created to work as an offline database per se; only to offer an "offline mode" for your online data.
Is it possible to use SQLite as a relational database from Google App Engine? (Java) I need read/write access to it from the app itself.
Also, I am using Quercus for PHP, and if what I am asking for is possible, I can handle storing the database myself.
No, it is not possible. This would require write access to the filesystem, which App Engine does not allow.
SQL database support (MySQL like) is planned, but no release data has been given. For now, use the datastore.
I know it's a super old question and nothing concerning read-only properties of App Engine has changed since then... But actually you can use sqlite on Google App Engine. There is a writable /tmp directory (https://cloud.google.com/appengine/docs/standard/java-gen2/using-temp-files). If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.
The following problems are connected with this approach:
This directory is "in-memory". So if you want to use really large sqlite file, you may face problems with RAM.
Each node of the app gets its own copy of the database. If you save something on one node, these changes will not be seen by other nodes. And the new data will be lost if the app scales to 0.