0

I tried 2 ways.

First:

getUserReference()?.get()?.addOnSuccessListener {}

Second:

getUserReference()?.addListenerForSingleValueEvent(object : ValueEventListener {
    override fun onDataChange(snapshot: DataSnapshot) {}
    override fun onCancelled(error: DatabaseError) {}
})

But as I understand it, it returns all the data. Regardless of whether there was a data update or not. I want to upload data only if there have been changes on the server. How can this be done? Or I don't understand something.

Victor
  • 331
  • 2
  • 7

1 Answers1

2

There is nothing built into Firebase for only getting updated data. If you want that, you will have to:

  1. Add a timestamp to each child node, indicated when it was last updated.
  2. Use a query to only get the updated data: ref.orderByChild("lastUpdated").startAt(System.currentTimeMillis())

This has been covered quite a few times before, so I recommend checking out the answers to some of these questions, including:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807