android - Removing ChildEventListener -
i'm using firebase childeventlistener
added n-number of times node
data db.
now i'm trying remove childeventlistener
, not seem work , duplicate data.
query = firebasedatabase.getinstance().getreference() .child("chat") .child("room-messages") .child(roomid) .orderbychild("timestamp") .limittolast(index); paginationlistener = query.addchildeventlistener(new childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { log.d(tag, datasnapshot.getkey() + " - single value"); try { message message = datasnapshot.getvalue(message.class); message.setid(datasnapshot.getkey()); eventbus.getdefault().post(new getpaginatedmessage(message)); } catch (runtimeexception e) { log.d(tag, "type cast exception caught"); } }
and removing listener like
if (query != null && paginationlistener != null) { query.removeeventlistener(paginationlistener); }
it doesn't seem work , duplicate data. appriciated
calling removeeventlistener()
removes listener location. not fire events data received after call it. may still fire events data it's received.
jonny's answer on firebase-talk group same behavior:
events queued asynchronously , potentially run on different thread, there might have been events queued before call removeeventlistener.
Comments
Post a Comment