Presence in android using smack


I am using smack in Android in order to create a chat application, The issue i now face is , when the user is still online, the other party receives an “unavailable” status message, and also, sometimes, it is when one user sends a msg, the presence gets broadcasted at the other end. Why does that happen?

The code to send the presence is as under:

Presence presence = new Presence(isOnline ? Presence.Type.available : Presence.Type.unavailable);

presence.setMode(isOnline ? Presence.Mode.available : Presence.Mode.away);

presence.setStatus((isOnline) ? “online” : “offline”);



while to check if the user is online or offline, i use the followng method:

public boolean isUserAvailable(String userId) {

final Roster roster = Roster.getInstanceFor(connection);

return roster.getPresence(userId).isAvailable();



Please assist, as this is really inconsistent at times.