android - Firebase looping, How can I stop this from looping -
i have been trying set value change listener this:
final databasereference chat_ref = firebasedatabase.getinstance().getreference(constants.arg_chat_rooms + "/" + room_type_1); chat_ref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(final datasnapshot datasnapshot) { showalert(datasnapshot); } @override public void oncancelled(databaseerror databaseerror) { } });
the problem that, parenthesis after showalert
method keeps looping over, creating several alerts when want one.
what causing loop , how can address it? appreciated!
i not sure getting wrong, because loops well:
chat_ref.addlistenerforsinglevalueevent(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { showalert(datasnapshot); } @override public void oncancelled(databaseerror databaseerror) { } });
you have several alerts because of way in valueeventlistener
works. remember valueeventlistener
not loop
interface
. please see more details here. , see in offical doc, triggered every time data @ particular location changes.
to solve this, call of showalert()
out ondatachange
method.
hope helps.
Comments
Post a Comment