I read this in the documentation:
To use offline persistence, you don't need to make any changes to the code that you use to access Cloud Firestore data. With offline persistence enabled, the Cloud Firestore client library automatically manages online and offline data access and synchronizes local data when the device is back online.
...
For Android and iOS, offline persistence is enabled by default. To disable persistence, set the
PersistenceEnabled
option tofalse
.
In Android, I created my Firestore reference as follows:
final FirebaseFirestore db = FirebaseFirestore.getInstance();
I assume persistence is enabled by default.
I will try to explain with this image what's happening:
Letter A
- I added this document yesterday and I could read it normally with the device online.
- Today I can read this document with the device offline.
Letter B
- Yesterday I added this document too. The device was online AFTER the existence of this document but I did not read it. It was added but never read.
- Today, with the device offline, I tried to read this document, but I could not. (Why was it not synced while the device was online?)
Letter C
- Yesterday I had access to collection
6
, document03000503
, but persistence is not enabled for the entire collection? - So when I added the document
03030501
, this document was not synchronized with the device when it was online? If I don't read the document one time while online there is not synchronization, and synchronization is not for all documents in collection6
? - Is it possible for collection
6
to synchronize when I add a document while online?
Here is my code for reading the documents:
public void launchFirestore() {
final FirebaseFirestore db = FirebaseFirestore.getInstance();
String fechaDD = strFechaHoy.substring(6, 8);
String fechaMM = strFechaHoy.substring(4, 6);
String fechaYYYY = strFechaHoy.substring(0, 4);
DocumentReference calRef = db.collection(CALENDAR_PATH).document(fechaYYYY).collection(fechaMM).document(fechaDD);
calRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot calSnapshot,
@Nullable FirebaseFirestoreException e) {
DocumentReference dataRef=calSnapshot.getDocumentReference(VISPERAS_ID);
if (e != null || dataRef==null) {
launchVolley();
return;
}
if (calSnapshot != null && calSnapshot.exists()) {
dataRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot dataSnapshot) {
//Log.d(TAG,"---"+dataSnapshot.toString());
mBreviario = dataSnapshot.toObject(Breviario.class);
showData();
}
});
} else {
launchVolley();
}
}
});
}
lh
collection. How I can do that? It would not be very expensive? – Lemuroid