我使用Smack by XMPP server(openFire)开发了一个聊天应用程序。为了获取传入的消息,我使用PacketFilter 这是传入的消息代码:-
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
incomemsg = message.getBody();
if (incomemsg != null) {
String fromName = StringUtils.parseBareAddress(message.getFrom());
frmname = message.getBody();
Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
// Add the incoming message to the list view
mHandler.post(new Runnable() {
public void run() {
// show the msg of chat in right side.
showMessage(frmname,false);
scrollContainer.getFocusables(scrollContainer.getChildCount());
}
});
}
}
}, filter);
但我想在活动关闭或停止或销毁期间删除 paketListener。我按照这个http://community.igniterealtime.org/thread/28921删除数据包侦听器但没有找到解决方案。
请检查。谢谢你的时间。