简体   繁体   中英

Number of times data snapshot is received

mAuth.currentUser?.uid?.let {
    FirebaseDatabase.getInstance().getReference().child("users").child(it).child("snaps")
        .addChildEventListener(object: ChildEventListener{
            override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
                emails.add(snapshot.child("from").value as String)
                snaps.add(snapshot)
                adapter.notifyDataSetChanged()
            }

In the above code I get the snapshot from firebase database. I have 2 children under snaps .

My question is does dataSnapshot contain all the children as one or will I get 2 dataSnapshot where each snapshot represent one child?

In other words, snaps array list size is 1 or 2?

For this code, it will be the UID of the currently signed in user. The code will add a single listener to the child node called "snaps" under "users/{it}".

The provided callback will not receive updates for any other child under "users". In other words, it will not see other users' snaps. It doesn't matter how many users there are.

The callback will be invoked once for each existing child under the user's "snaps" child, then again for future changes to any child.

This is all behavior you can observe yourself by adding logging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM