// Register a listener for a last activity query
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
LastActivity message = new LastActivity();
message.setType(IQ.Type.RESULT);
message.setTo(packet.getFrom());
message.setFrom(packet.getTo());
message.setPacketID(packet.getPacketID());
message.setLastActivity(getIdleTime());
LastActivityManager.this.connection.sendPacket(message);
}
}, new AndFilter(new IQTypeFilter(IQ.Type.GET), new PacketTypeFilter(LastActivity.class)));