How to get nested Child from Firebase Database Using Android?

后端 未结 3 1278
北海茫月
北海茫月 2021-01-16 11:55

I want to get list of all Allowed child from this type of JSON Tree:

databaseRef.child(\'Users\').child(\'Allowded\').addValueEventListener(new ValueEventLis         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-16 12:21

    Firebase listeners fire for both the initial data and any changes.

    If you're looking to synchronize the data in a collection, use ChildEventListener. If you're looking to synchronize a single object, use ValueEventListener. Note that in both cases you're not "getting" the data. You're synchronizing it, which means that the callback may be invoked multiple times: for the initial data and whenever the data gets updated.

    FirebaseRef.child("message").addValueEventListener(new ValueEventListener() {
     @Override
    public void onDataChange(DataSnapshot snapshot) {
      System.out.println(snapshot.getValue());  //prints "Do you have data? You'll 
        love Firebase."
     }
    @Override
     public void onCancelled(DatabaseError databaseError) {        
    }
     });
    

提交回复
热议问题