I am trying to create a service for a chat widget using XMPP that collects chat messages when they are sent to the user.
I created a service, and in onStart I use AsyncTask to connect to the chat server, and then configures the batch.
Here is the code for the packer listener:
public void setConnection(XMPPConnection connection) { if (connection != null) { // Add a packet listener to get messages sent to us PacketFilter filter = new MessageTypeFilter(Message.Type.chat); connection.addPacketListener(new PacketListener() { public void processPacket(Packet packet) { Message message = (Message) packet; if (message.getBody() != null) { String fromName = StringUtils.parseBareAddress(message .getFrom()); Log.v(TAG, "Got:" + message.getBody()); // messages.add(fromName + ":"); // messages.add(message.getBody()); } } }, filter); } }
The problem is that she stops listening when you are idle for a while. If I immediately send chat messages, they will get an output.
Does the service somehow stop? Is this a suitable place to place a packer?
thanks
athor source share