I use asmack for an IM application for Android, where I use a remote service with an AIDL interface.
Inside the onStartCommand method of my service, I write code as shown below. I create a connection and then connect to it using this. When someone launches my application inside the onCreate method of my application’s main activity, start my getApplicationContext.StartService(serviceIntent) . It works fine, but after a few minutes (sometimes 10 minutes and some time more than ten) messageListener , which I attach to the service stop to receive messages. But I know that the connection exists, because at the same time I use xmppConnection to send a message sending a message to user B, but he does not listen to messages from user B. I do not know why my listener stopped hearing the message.
public int onStartCommand(final Intent intent, final int flags, final int startId) { ConnectionConfiguration config = new ConnectionConfiguration(URL, MyPort, Host); xmppConnection = new XMPPConnection(config); xmppConnection.connect(); xmppConnection.login(" someid@sample.com ", "testpass"); xmppConnection.addPacketListener(myMessageListener, new PacketTypeFilter(Message.class)); return START_STICKY; } private PacketListener myMessageListener = new PacketListener() { public void processPacket(Packet packet) { Message msg = (Message) packet; } }
Please guide.
aftab source share