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);