Firebase监听器未被调用

时间:2018-03-18 09:35:43

标签: java android firebase firebase-realtime-database

  

我想检查节点是否已创建。我刚刚在下面实现了Toa​​st,但没有任何敬酒。

注意:firebase DataBase现在为Total null

  DatabaseReference reference = FirebaseDatabase.getInstance().getReference();

    reference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Toast.makeText(RegisterActivity.this, dataSnapshot.getKey() + "", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Toast.makeText(RegisterActivity.this, databaseError.toString() + "", Toast.LENGTH_SHORT).show();
        }
    });

其次是我试过的代码,但没有运气

 DatabaseReference reference = FirebaseDatabase.getInstance().getReference();

    reference.child("device_id");

    reference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Toast.makeText(RegisterActivity.this, dataSnapshot.getKey() + "", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Toast.makeText(RegisterActivity.this, databaseError.toString() + "", Toast.LENGTH_SHORT).show();


        }
    });

1 个答案:

答案 0 :(得分:0)

更改此行代码:

${= ${Str} == ABC =}

使用:

reference.addListenerForSingleValueEvent(new ValueEventListener() {