I have been writing an app using the new cloud firestore database. It works great except the fact that many things are not working smoothly when offline although the offline persistence is enabled. For instance I do the following:
ref.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
//Do something
} else {
//Do another thing
}
}
});
However the onComplete
method is never called when offline. I want to close the activity and show some Snachbar once this happens. But as it never does, the activity remains open. I am using android studio emulator.
Thanks
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.
You can use both Firebase Realtime Database and Cloud Firestore in your app, and leverage each database solution's benefits to fit your needs. For example, you might want to leverage Realtime Database's support for presence, as outlined in Build Presence in Cloud Firestore.
It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.
Operations that write to the database are defined to signal completion once they've actually committed to the backend. As a result this is working as intended: while offline they won't signal completion.
Note that the Firestore clients internally guarantee that you can read your own writes even if you don't wait for completion of the task from delete.
For the most part this means that you shouldn't need to wait for this task to complete. Is there any particular reason you're interested in doing so?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With