On iOS, if you change or remove data from Firebase and start the app, onChildChanged or onChildRemoved are getting called to deliver the changed/removed data. On Android, the methods are only called when the app is running but not after starting. (Why I need this: It's crucial for syncing eg for users using multiple devices). This is my code:
transactionsRef.child(depotname).addChildEventListener(object : ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
// Handle event here } // Other override methods, such as onChildChanged, onChildRemoved, etc. })
println("onChildAdded : ${snapshot.key}}")
}
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {
//TODO("Not yet implemented")
println("onChildChanged : ${snapshot.key}}")
}
override fun onChildRemoved(snapshot: DataSnapshot) {
//TODO("Not yet implemented")
println("onChildRemoved : ${snapshot.key}}")
}
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {
//TODO("Not yet implemented")
}
override fun onCancelled(error: DatabaseError) {
//TODO("Not yet implemented")
}
})
Just FYI, onChildAdded is called immediately at the app starts.