I am using asmack api for the Android XMPP Integration...
After the successful authentication for the xmpp connection, I have used PacketListener for the incoming message notification.
My application is tab based application. When I am moving to chat activity by clicking on the friends list, my packet listener is added to the connection in OnCreate method.
The issue is that as many times Im moving to this screen that number of listeners are added and Im getting same message multiple times.
Anysolution for this Issue ?
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
PacketListener pListener = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message
.getFrom());
Log.i("XMPPClient", "Got text [" + message.getBody()
+ "] from [" + fromName + "]");
messages.add(fromName + ":");
messages.add(message.getBody());
// Add the incoming message to the list view
mHandler.post(new Runnable() {
public void run() {
setListAdapter();
}
});
}
}
};
connection.addPacketListener(pListener, filter);
@Vishal. You should not add this listener in any of your activity file, just add these listeners in your Android Service which should run with a single instance all the time.
Thanks
I got the same issue. This is what I did,
OnResume()
{
connection.removePacketListener(yourlistener);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With