Firestore Offline Write / Add Not Working

We can force Firestore to load records into the local cache and read these records. However, we cannot update the record and cannot add a new record.

They even tried the same code ( https://github.com/firebase/quickstart-android ), but it seems they can’t get a standalone write / insert working - only read.

When we call this function offline, it is called OnFailureListner and throws an exception

 @Override
public void onRating(Rating rating) {
    // In a transaction, add the new rating and update the aggregate totals
    addRating(mRestaurantRef, rating)
            .addOnSuccessListener(this, new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.d(TAG, "Rating added");

                    // Hide keyboard and scroll to top
                    hideKeyboard();
                    mRatingsRecycler.smoothScrollToPosition(0);
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.w(TAG, "Add rating failed", e);

                    // Show failure message and hide keyboard
                    hideKeyboard();
                    Snackbar.make(findViewById(android.R.id.content), "Failed to add rating",
                            Snackbar.LENGTH_SHORT).show();
                }
            });
}
+4
source share
1 answer

, Firestore , ( ). Firestore , .

Android . developer.android.com:

- , . . , , , . , , , . .

, Service, FirebaseFirestore .

, Android: https://developer.android.com/guide/components/services.html

-2

Source: https://habr.com/ru/post/1688654/


All Articles