Firebase数据库无法检索数据

时间:2016-06-30 02:47:03

标签: android firebase firebase-realtime-database

这是我第一次使用firebase,并且我有一些方法都包含在同一个类中,并且没有接缝才能正常工作。 nameExists总是返回false,即使我在控制台中可以看到存储在name中的值不为null。 userStatus是此类中的DataSnapshot字段。

update

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

您忽略了char code[]="\x90\x90\x90\x90\x90\x90\x90\x90"; //a static string contains executable code int main() { int *return_address; //Pointer to the return address - uninitialized return_address = (int *)&return_address + 2; //Initializing the return address - according to stack layout (*return_address) = (int)code; //Overwriting the return address with the code's address } 回调的异步性质。添加侦听器时,通常需要从Firebase服务器获取值,然后ValueEventListener回调才能提供该值。回调会异常触发,通常在添加侦听器后几毫秒。

在您的代码中,onDataChange()添加getUserStatus(),然后将其删除并返回statusesListener。所有这些都发生在userStatus被触发之前,因此onDataChage()的值不变。

此外,添加并立即删除userStatus并不是典型的用例,并且鉴于侦听器的异步性质,可能会导致它永远不会触发。最好使用Query.addListenerForSingleValueEvent()添加侦听器,它会为您提供一次值,并且不需要删除侦听器。

相关问题