【发布时间】:2018-04-15 19:10:55
【问题描述】:
我们能够让 Firestore 将记录下载到本地缓存并读取这些记录。但是,我们无法更新记录,也无法添加新记录。
甚至尝试了一些相同的代码 (https://github.com/firebase/quickstart-android),但似乎无法让离线写入/插入工作 - 只能读取。
当我们离线调用这个函数时,它会被调用 OnFailureListner 并抛出异常
@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();
}
});
}
【问题讨论】:
标签: android firebase google-cloud-firestore