> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# User Presence

> Track and subscribe to user online/offline status and presence updates in your Android app

> [accordion] AI Integration Quick Reference
>
> > [tab] Kotlin
> >
> > ```kotlin theme={null}
> > // Subscribe to presence during init
> > val appSettings = AppSettings.AppSettingsBuilder()
> >     .subscribePresenceForAllUsers()
> >     .setRegion("REGION")
> >     .build()
> > CometChat.init(context, "APP_ID", appSettings, callback)
> >
> > // Add user listener
> > CometChat.addUserListener("LISTENER_ID", object : CometChat.UserListener() {
> >     override fun onUserOnline(user: User?) {
> >         Log.d(TAG, "${user?.name} is online")
> >     }
> >     override fun onUserOffline(user: User?) {
> >         Log.d(TAG, "${user?.name} is offline")
> >     }
> > })
> >
> > // Remove listener (important!)
> > CometChat.removeUserListener("LISTENER_ID")
> > ```
>
> > [tab] Java
> >
> > ```java theme={null}
> > // Subscribe to presence during init
> > AppSettings appSettings = new AppSettings.AppSettingsBuilder()
> >     .subscribePresenceForAllUsers()
> >     .setRegion("REGION")
> >     .build();
> > CometChat.init(context, "APP_ID", appSettings, callback);
> >
> > // Add user listener
> > CometChat.addUserListener("LISTENER_ID", new CometChat.UserListener() {
> >     @Override public void onUserOnline(User user) {
> >         Log.d(TAG, user.getName() + " is online");
> >     }
> >     @Override public void onUserOffline(User user) {
> >         Log.d(TAG, user.getName() + " is offline");
> >     }
> > });
> >
> > // Remove listener (important!)
> > CometChat.removeUserListener("LISTENER_ID");
> > ```

User Presence lets you know if a user is available to chat. Configure presence subscription during `init()`, then listen for online/offline events via `UserListener`.

## Real-time Presence

Based on the `AppSettings` configured during `init()`, the logged-in user receives presence updates for other users.

`AppSettingsBuilder` provides three subscription options:

* `subscribePresenceForAllUsers()` — Receive presence for all users in the app.
* `subscribePresenceForRoles(List<String> roles)` — Receive presence only for users with specified roles.
* `subscribePresenceForFriends()` — Receive presence only for friends.

If none are set, no presence events are sent.

Register `UserListener` in `onResume()` and remove it in `onPause()`.

> [tab] Java
>
> ```java theme={null}
> private String listenerID = "UNIQUE_LISTENER_ID";
>
> CometChat.addUserListener(listenerID, new CometChat.UserListener() {
>   @Override public void onUserOnline(User user) {
>     Log.d(TAG, user.getName() + "is online.");
>   }
>   @Override public void onUserOffline(User user) {
>     Log.d(TAG, user.getName() + "is offline.");
>   }
> });   
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val listenerID:String = "UNIQUE_LISTENER_ID"
>
> CometChat.addUserListener(listenerID,object :CometChat.UserListener(){
>   override fun onUserOffline(user: User?) {
>     Log.d(TAG, user?.name + "is offline.")
>   }
>   override fun onUserOnline(user: User?) {
>     Log.d(TAG, user?.name + "is online.")
>   }
> })
> ```

| Parameter | Description |
| - | - |
| `listenerID` | An ID that uniquely identifies that listener. We recommend using the activity or fragment name. |

Remove the listener in `onPause()` when the activity or fragment is no longer in use.

> [tab] Java
>
> ```java theme={null}
> private String listenerID = "UNIQUE_LISTENER_ID";
>
> CometChat.removeUserListener(listenerID);     
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val listenerID:String = "UNIQUE_LISTENER_ID"
>
> CometChat.removeUserListener(listenerID)   
> ```

> [!WARNING]
>
> Always remove listeners when they're no longer needed (e.g., in `onPause()` or `onDestroy()`). Failing to remove listeners can cause memory leaks and duplicate event handling.

## User List Presence

When you [retrieve the list of users](https://www.cometchat.com/docs/sdk/android/v4/retrieve-users.md), each [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user) object includes:

* `status` — `"online"` or `"offline"`
* `lastActiveAt` — Unix timestamp of when the user was last online (useful for "Last seen" indicators)

***

***

## Next Steps

> [card] [Retrieve Users](https://www.cometchat.com/docs/sdk/android/v4/retrieve-users.md)
>
> Fetch user lists with presence information

> [card] [Connection Status](https://www.cometchat.com/docs/sdk/android/v4/connection-status.md)
>
> Monitor SDK connection state and handle reconnection

> [card] [User Management](https://www.cometchat.com/docs/sdk/android/v4/user-management.md)
>
> Learn about user objects and properties

> [card] [Real-Time Listeners](https://www.cometchat.com/docs/sdk/android/v4/real-time-listeners.md)
>
> Understand all available event listeners


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.