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 create my Firestore reference as follows:
final FirebaseFirestore db = FirebaseFirestore.getInstance();
Then, I assume persistence is enabled by default.
I will try to explain with this image what's happening:
A
I added this document yesterday and i readed this normally with the device connected.
Today i can read this document with the device off-line.
B
- Yesterday I added this document too. The device was on-line after the existence of this document but i don't readed this document. It was added but never read.
- Today, with the device off-line i try to read this document, but is not possible. (Why was not synched during the device was on-line?)
C
Yesterday I haved access to collection 6
, document 03000503
...
The persistence is not enabled for the entire collection?
When I add the document 03030501
, this document is not synchronized with the device when it's on-line? If i don't read the document one time on-line there is not synchronization? In this case the synchronization is not for all documents in collection 6?
I need that if I add one document to collection 6 the device synchronize this document when it's on-line without having to enter in that new document. This is possible?
Here is the code for read 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();
}
}
});
}