Android Firebase与addListenerForSingleValueEvent()一起使用时返回旧数据集
我要进行一次查询,不想保留一个侦听器,以便在发送手动触发器时更新数据 我的问题是这样的:Android Firebase与addListenerForSingleValueEvent()一起使用时返回旧数据集,android,firebase,firebase-realtime-database,nativescript,angular2-nativescript,Android,Firebase,Firebase Realtime Database,Nativescript,Angular2 Nativescript,我要进行一次查询,不想保留一个侦听器,以便在发送手动触发器时更新数据 我的问题是这样的: var ref = this.instance.child('/user/manish/today/events') .orderByChild('endDateTime') .endAt(endEventTime) .limitToLast(10) .addListenerForSingleValueEvent(this.previousEventListeners);
var ref = this.instance.child('/user/manish/today/events')
.orderByChild('endDateTime')
.endAt(endEventTime)
.limitToLast(10)
.addListenerForSingleValueEvent(this.previousEventListeners);
this.previousEventListeners = new com.google.firebase.database.ValueEventListener({
onDataChange: (snapshot) => {
console.log("Value from native firebase access");
console.dump(this.testing(snapshot.getValue()));
let result = {
value : this.testing(snapshot.getValue()),
type : "ValueChanged"
};
console.dump(result);
},
onCancelled: (databaseError) => {
console.log(databaseError.getMessage());
hideActivtiyIndicator();
}
});
即使添加了与查询条件匹配的新记录,它也会返回相同的数据集
谢谢是的,我们在自己的应用程序中体验到了这种行为。如果需要启用磁盘持久性的最新数据,则需要订阅所有事件值更新,而不仅仅是调用单个值。这是特别令人困惑的,因为尽管有这种行为,Firebase仍然会调用服务器以获取一个新值——它只是不会将该值返回给您 我就此事向Firebase提出了支持请求,他们说这是意料之中的行为。我还建议他们澄清文档,他们说
感谢您的全面反馈。我们确实重视开发人员的这种投入。这将包括在我们的功能请求列表中,并将与我们的工程师讨论。不幸的是,我无法分享任何时间线或明确的细节,因为这将由内部监控。
希望这能澄清情况。值得一提的是,我们通过添加一个附加功能的
FIRDatabaseReference
类别(iOS,为您的平台使用适当的隐喻)来解决这个问题。它调用SingleValueEvent
,然后在500毫秒后再次调用,将两次值都返回给调用者。(回调时使用弱引用,以防呼叫者同时离开。)500ms似乎是一个很好的选择-用户可以立即看到一个显示值,如果他们脱机或网络速度慢,这就是他们所看到的。但是,如果他们在线并且有良好的网络访问能力,这将在不久之后为他们提供最新的数据。这很可能是您在使用磁盘持久性。Firebase的磁盘持久性和addListenerForSingleValueEvent()不能很好地混合。看见