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) {
addRating(mRestaurantRef, rating)
.addOnSuccessListener(this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "Rating added");
hideKeyboard();
mRatingsRecycler.smoothScrollToPosition(0);
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Add rating failed", e);
hideKeyboard();
Snackbar.make(findViewById(android.R.id.content), "Failed to add rating",
Snackbar.LENGTH_SHORT).show();
}
});
}
source
share