I am trying to write a listener for a asmack packet. What ends up happening is the listener sometimes just doesn't get the packet and process it. Here is some of the code:
try {
XMPPMethods.getConnection().addPacketListener( new PacketListener() {
@Override
public synchronized void processPacket(Packet packet) {
if (packet.getPacketID().equals(lastCustomIQId)) {
android.os.Message msg = new android.os.Message();
msg.obj = privateData;
msg.what = XMPPMethods.ADD_CONTACT_RESULTS;
AddContact.addContactHandler.sendMessage(msg);
}
}
}, new PacketIDFilter(lastCustomIQId));
Note that this IS inside of the doInBackground(string... params) part of an asynctask.
The packet is being sent using:
JIDIQ.setPacketID(lastCustomIQId);
JIDIQ.setFrom(XMPPMethods.getCurrentUserFullUserName());
JIDIQ.setType(Type.GET);
XMPPMethods.getConnection().sendPacket(JIDIQ);
Where the JIDIQ is an asmack IQ. This code all runs correctly MOST of the time. But sometimes the PacketListener just doesn't receive the packet sent. I'm wondering if I should be using a PacketCollector instead, or if the listener is somehow dying. Does anyone know why this wouldn't receive the packet? Any knowledge of this subject would be greatly appreciated!