Android - Firestore Offline Data Synchronization
The firestore documentation says:
Cloud Firestore caches data that your app is actively using, so the app can write, read, listen to, and query data even if the device is offline. When the device comes back online, Cloud Firestore synchronizes any local changes back to Cloud Firestore.
Now, I have tested this and, apparently, device coming back online is not all that it takes for the synchronization to happen.
I tested that by:
- Turning on "Airplane mode" on my emulator
- Trying to send a data to firestore*
- Closing my app
- Turning off "Airplane mode" on my emulator
* I used FirebaseFirestore.getInstance().collection("foo").document().set(bar)
On the end of this test, the data was not sent to firestore remote database. I needed to open my app again in order for the data to be sent.
But then, I still wasn't sure what exactly was triggering the synchronization. Is it only my app being open or does it needs to have an open socket to firestore?
I tested one last thing, which was:
- Turning on "Airplane mode" on my emulator
- Trying to send a data to firestore*
- Closing my app
- Altering my code so the app stays on the splash screen
- Turning off "Airplane mode" on my emulator
- Opened my app
On the end of this test, the data was not sent to firestore remote database.
But then, once again, I still wasn't sure what exactly was triggering the synchronization. It's probably the open socket, but if so, does it need to be open on a query related to my collection?
My final question is:
What exactly does trigger the synchronization?
Answer
Is it only my app being open or does it needs to have an open socket to firestore?
It depends on what "my app being open" means. If it means on foreground, that might not make too much sense since you can have jobs running on background with an open socket to Firestore.
It's probably the open socket, but if so, does it need to be open on a query related to my collection?
No, it does not. Any CRUD action on any part of your database will make the synchronization starts, whether it is by querying through a collection or fetching, saving, updating or removing a document.
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View