in order to have atomic data operations in my Firebase Android applications, I'm using the updateChildren(Map<String, Object> update)
method to set multiple values with a single command (this prevents data inconsistencies.
In some cases, upon writing data I also need to set priorities in order for the index elements to be sorted correctly.
Using the 'not atomic' setValue(Object value, Object priority)
operation, it is possible to write a value and set the priority at the same time. Using the updateChildren()
commmand does not allow to set priorities.
In order to set the priorities of newly created data, I currently call setPriority()
in the CompletionListener
of the updateChildren()
command. This works, but causes strange UI behavior (elements are added to the bottom of the list, and after this they move to the correct place).
What would be the recommended way to handle this correctly?