我有下一個 Firestore 方案:集合“用戶”-檔案 user_id-集合“trips”-檔案 trip_id-集合“請求”-檔案 request_user_id 欄位:和布爾欄位 <is_accepted>
在我的一個頁面上,我想收聽請求的實時更新:如果 <is_accepted> 從 0 變為 1(這意味著用戶被接受旅行)。
我寫了 EventListener 來跟蹤它:
FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
firebaseFirestore
.collection("users")
.document(user_id)
.collection("trip")
.document(trip_id)
.collection("requests")
.whereEqualTo("accepted", 1)
.orderBy("timestamp", Query.Direction.DESCENDING)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
Log.d("Hello", "Triggered");
if (error == null) {
if (value != null) {/// some actions}}
第一次在頁面上讀取資料時效果很好,但是當我在檔案中進行更新時,例如:
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("timestamp", Timestamp.now());
hashMap.put("accepted", 1);
firebaseFirestore
.collection("users")
.document(user_id)
.collection("trips")
.document(trip_id)
.collection("requests")
.document(joined_user_id)
.update(hashMap);
聽眾沒有看到任何變化。有什么問題?
uj5u.com熱心網友回復:
您的偵聽器僅被添加到accepted已設定為 1的檔案中。.whereEqualTo("accepted", 1)注冊偵聽器時洗掉,或將其更改為 0 以僅偵聽尚未接受的檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/476540.html
上一篇:Androidstudioide上的頁面設計不同,當我將其構建到我的Android手機中時
下一篇:Kotlin從日期中提取時間
