Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addOnCompleteListener not called offline with cloud firestore

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

like image 903
edmond Avatar asked Oct 10 '17 17:10

edmond


People also ask

Does firebase firestore work offline?

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.

Can I use realtime database and firestore at the same time?

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.

Is cloud firestore better than realtime database?

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.


1 Answers

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?

like image 112
Gil Gilbert Avatar answered Sep 28 '22 19:09

Gil Gilbert