I need to use a Firebase database, to do this I store a copy of the snapshot, retrieved using onDataChange()
function of a listener, inside a global variable.
While I'm using the global copy, if a change happens in the Firebase database from another device, won't the global copy be changed whilst I'm using it and thus corrupting it? If so is there a known solution to this?
The contents of a DataSnapshot object will never change. They are immutable.
If you reassign a global variable with a new snapshot, obviously the global variable will change. But as long as you are working with the snapshot through a local variable, the code that works with the local variable will not see the update.