aft*_*tab 6 android xmpp smack android-intent asmack
我正在使用asmack作为一个Android IM应用程序,我正在使用AIDL接口的远程服务.
在onStartCommand我的服务方法内部,我编写如下代码.我创建连接,然后使用它登录.当任何人在我的应用程序onCreate的主要活动方法中运行我的应用程序运行我的服务getApplicationContext.StartService(serviceIntent).它工作正常,但是messageListener我在服务内部附加的几分钟(有时10分钟,一些时间超过10分钟)停止接收消息.但我知道连接存在,因为同时我用xmppConnection它来发送消息它正在向用户B发送消息但是它没有收听来自用户B的消息.我不知道为什么我的听众停止听到消息.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
请指导.