当Android设备再次联机时,Firestore需要很长时间才能同步数据

时间:2018-03-29 15:25:20

标签: java android firebase google-cloud-firestore

这个过程很简单。我的android正在使用以下方法监听Firestore数据库更改:

    final DocumentReference docRef = db.collection("collection").document("123");
    docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
        @Override
        public void onEvent(@Nullable DocumentSnapshot snapshot,
                            @Nullable FirebaseFirestoreException e) {
            if (e != null) {
                return;
            }

            if (snapshot != null && snapshot.exists()) {
                message.setText(snapshot.getData().get("status").toString());
            } else {
                Log.d("", "Current data: null");
            }
        }
    });
}

此方法位于我的活动的onCreate方法中。这很好用。当我在Firestore上更新值“status”时,它会立即在我的Android设备上更新。

然而,当我关闭我的Wi-Fi和3G时,更新Firestore上的数据,再次打开wi-fi和3G,再次同步数据大约需要2分钟。听众需要花费很长时间才能“听到”Firestore数据库中的新内容。这是正确的行为吗?或者我错过了什么?

0 个答案:

没有答案