我有一个aSmack已实施的应用程序,(8-4.0.5),因为我们知道它有一个内部重新连接管理,但它没有令人满意,因为有些时候我们应该等待5分钟重新连接发生,而我们现在知道的是这样做的好时机,所以我实现了这个:
private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
if(isNetworkAvailable()){
if(MyService.myServiceInstance!=null){
if(!MyService.connection.isConnected() || !MyService.connection.isAuthenticated()){
MyService.myServiceInstance.performReconnect();
// Which goes to Connect() and Authenticate()
}
}
LMApplication.getInstance().getPresistentJobManager().onNetworkChange(true);
}
}
};
但问题是有时他们都试图同时连接(我的经理和内置管理器),结果是,他们下次一次又一次地重新连接,每次我都收到这个错误:
11-10 14:58:09.069: W/PacketWriter(26439): Exception writing closing stream element
11-10 14:58:09.069: W/PacketWriter(26439): java.io.IOException: BufferedWriter is
closed
11-10 14:58:09.069: W/PacketWriter(26439): at
java.io.BufferedWriter.checkNotClosed(BufferedWriter.java:130)
11-10 14:58:09.069: W/PacketWriter(26439): at
java.io.BufferedWriter.flush(BufferedWriter.java:122)
11-10 14:58:09.069: W/PacketWriter(26439): at
org.jivesoftware.smack.util.ObservableWriter.flush(ObservableWriter.java:44)
11-10 14:58:09.069: W/PacketWriter(26439): at
org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)
11-10 14:58:09.069: W/PacketWriter(26439): at
org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)
11-10 14:58:09.069: W/PacketWriter(26439): at
org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)
我猜是因为1已经完成了这项工作并关闭了作者,而另一个人看到作者已关闭,断开了连接!就像2个嫉妒的孩子一样!
所以有什么想法我可以在这里做什么,比如我如何禁用影响,或强制重新连接?
答案 0 :(得分:0)
我不得不删除aSamack自动连接系统,我自己完全完成了,这样我的应用程序就获得了稳定性。