Why when the XMPP connection disconnect the presence type user change from unavailable to available

2.1k Views Asked by At

How to log out correctly when I close the application and stop the ping execute?

When I run the logout below each line code work perfect,

But if I run the code lines:

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

I get user offline/unavailable.//But the connection alive

Then I want to disconnect the connection so I run the line code.

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

I have more one problem when the connection die i get something like ping.

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

There are 1 best solutions below

0
On

I solve the problem by the next code.

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");

    }
}