This is just an example of what my code is like. Right now, if I print out the userName variable inside onDataChange, it works fine. But if I try printing userName outside,
This is something I've often found tricky with Firebase. The only real solutions I could suggest would be to make sure that any code where you need to access the Firebase variables is either:
1) Inside the onDataChange method.
2) Only called/accessed once the addListenerForSingleValueEvent onDataChange method has completed.