为什么当XMPP连接断开状态类型用户从不可用变为可用时

时间:2014-11-14 05:27:07

标签: android xmpp smack asmack

关闭应用程序并停止执行ping时如何正确注销?

当我在每行代码下运行注销时,完美无缺,

但如果我运行代码行:

 Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
            presence.setStatus(connection.getUser() + status);
            connection.sendPacket(presence);

我让用户离线/不可用。//But the connection alive

然后我想断开连接,以便运行行代码。

connection.disconnect();//I get user online/available and connection die.

当连接死掉时,我遇到了更多问题。

11-13 21:55:02.820: D/SMACK(7399): 09:55:02 PM SENT (1385370112):  
11-13 21:55:32.820: D/SMACK(7399): 09:55:32 PM SENT (1385370112):  
11-13 21:56:02.820: D/SMACK(7399): 09:56:02 PM SENT (1385370112):  
11-13 21:56:32.820: D/SMACK(7399): 09:56:32 PM SENT (1385370112):  
11-13 21:57:02.820: D/SMACK(7399): 09:57:02 PM SENT (1385370112):  
11-13 21:57:32.820: D/SMACK(7399): 09:57:32 PM SENT (1385370112):  
11-13 21:58:02.824: D/SMACK(7399): 09:58:02 PM SENT (1385370112):  
11-13 21:58:32.824: D/SMACK(7399): 09:58:32 PM SENT (1385370112):  
11-13 21:59:02.824: D/SMACK(7399): 09:59:02 PM SENT (1385370112):  
11-13 21:59:32.824: D/SMACK(7399): 09:59:32 PM SENT (1385370112): 

public void logOut(boolean unavailable, String status) {

    if (isConnectionAlive() || reConnectAndAuth()) {
        Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
        presence.setStatus(connection.getUser() + status);
        connection.sendPacket(presence);
        pm = null;
        connection.disconnect();
       //iscNNcet();
        Log.w("LogOut","LogOut");
    }
}

1 个答案:

答案 0 :(得分:1)

我通过下一个代码解决了这个问题。

public void logOut(boolean unavailable, String status,Context orgContext) {

if (isConnectionAlive() || reConnectAndAuth(orgContext)) {
    Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
    presence.setStatus(connection.getUser() + status);
    pm = null;

    try {
        connection.disconnect(presence);
    } catch (Exception exception) {
        exception.printStackTrace();
        connection.disconnect();
    }

    Log.w("LogOut", "LogOut");

    }
}