I have a query to firebase node with ChildEventListener shown in image link
now when I run this code
mMessageRef.child(ScrollAppUtils.firebaseId).child(child.key).orderByKey().limitToLast(1).addChildEventListener(object : ChildEventListener {
override fun onCancelled(p0: DatabaseError?) {}
override fun onChildMoved(p0: DataSnapshot?, p1: String?) {}
override fun onChildChanged(p0: DataSnapshot?, p1: String?) {}
override fun onChildAdded(p0: DataSnapshot?, p1: String?) {
Logger.d("inside onChild Added")
if (p0!!.hasChildren())
{
var lastMessage = p0.getValue(MessagesTwo::class.java)
var dialog = DefaultDialog(child.key, user.metaData.profileImage, user.metaData.name, arrayListUser, lastMessage, 2)
if (!listDialog.contains(dialog)) {
listDialog.add(dialog)
Logger.d(listDialog.size)
dialogListAdapter.setItems(listDialog)
dialogListAdapter.notifyDataSetChanged()
} else {
Logger.d("inside updateItemByID : ")
Logger.json(Gson().toJson(dialog))
dialogListAdapter.updateItemById(dialog)
dialogListAdapter.notifyDataSetChanged()
}
}
}
override fun onChildRemoved(p0: DataSnapshot?) {}
})
this listener simply doesn't work when a node not found, which I believe should work as ValueEventListener is working very well but I have some other problem with that listener so I am compelled to use this listener. Please suggest me what is I am doing wrong here?