title: Properly leave a chat room in smack Android
body: <p>In my appilcation I am using below method to leave from a chat room.</p>
  
  <pre><code> public void leaveChatRoom(String username)
  {
      Log.i("XMPP Chat Client", "User left chat room ");
      if(groupChat != null &amp;&amp; groupChat.isJoined())
      {
          try {
              Presence leavePresence = new Presence(Presence.Type.unavailable);
              leavePresence.setTo("groupchat@conference.xxx/" + username);
              connection.sendPacket(leavePresence);
              groupChat.leave();
  
  
          } catch (NotConnectedException e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>And to check whether the user is joined or not,</p>
  
  <pre><code>public boolean isJoinedGroup(String username)
      {
          boolean isConnected = false;
          if(groupChat != null &amp;&amp; groupChat.isJoined())
          {
              isConnected = true;
              Log.i("XMPP Chat Client", "Joined True");
          }
          return isConnected;
  }
  </code></pre>
  
  <p>This works fine if there is a successful chat server connection. But in some cases chat server connection loses. In that situation, I have to make the user leave from chat room and join back again automatically. So when I lose chat server connection, I will reconnect to chat server and call <code>leaveChatRoom</code> method and <code>join group</code> method together. I am getting <code>NotConnectedException</code> in line <code>groupChat.leave();</code> and when I check joined status,it always returns true. When I checked openfire admin panel, there is no user in groupchat occupants list. How can I properly remove user from groupchat in this situation?</p>