Firestore fails to retrieve data after reconnecting to the Internet

This issue was fixed by the release 17.1.5 of Cloud Firestore.

See the official changelog https://firebase.google.com/support/release-notes/android

Cloud Firestore now recovers more quickly from bad network states.


Using my reproduction project with the version 18.0.0, the issue is indeed not present.


From the official 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.

When you initialize Cloud Firestore, you can enable or disable offline persistence. So, when using the following line of code:

val firestoreSettings = FirebaseFirestoreSettings.Builder()
    .setPersistenceEnabled(false)
    .build()

You actually set the persistence to false, you are disabling this feature. To solve this, just remove this line of code. Firestore has .setPersistenceEnabled(true) by default.