In my application I\'m able to get children count by datasnapshot.getchildren(). But what should I do if I want to store that count in a variable?
mRefReg.ad
There's some info missing in your question, but I think I know what's going on. Listeners in Firebase are asynchronous, so you cannot set a variable that easy.
Options to go:
1) Declare your variable inside the onDataChange method.
2) Only use the variable when onDataChange method has completed.
3) Pass a callback function in the method where you have declared your listener.