我退出时的代码实现,这里的在退出后重新启动service是因为我的登录方法是写在service里面的:
public static void logOut(final Context mContext) {
//这里需要先将登陆状态改变为“离线”,再断开连接,不然在后台还是上线的状态
Presence presence = new Presence(Presence.Type.unavailable);
try {
XmppConfig.getInstance(mContext).sendStanza(presence);
if (connection.isConnected()) {
connection.disconnect();
connection.instantShutdown();
}
connection = null;
Intent intent = new Intent(mContext, ChatService.class);
mContext.startService(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
最后报的错误:
//我们向服务器发送的IQ消息,进行最后的鉴权
D/SMACK: SENT (1): <iq id='7XCqy-82' type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>Android</resource></bind></iq>
//服务器向我们返回的IQ结果:鉴权失败(<error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error>)
D/SMACK: RECV (1): <iq type="error" id="7XCqy-82" to="win-arbj87ei5km/22nzst74hd"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>Android</resource></bind><error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>