Skip to main content
Let users keep their most important chats at the top of the list. Pinning a conversation is per-user — it changes the order of the acting user’s own conversation list and is synced across their devices. A conversation can also be pinned globally for everyone by the app itself (a system pin). Let’s see how to work with pinned conversations in CometChat’s Android SDK.
Pinning a conversation with the SDK requires the Pin Conversation feature to be enabled for your app. You can check its availability at runtime using the feature flag.

Pin a Conversation

To pin a conversation, use the pinConversation method. Pass the UID of the other user (for a one-on-one conversation) or the GUID of the group, along with the matching conversation type. On success, the callback returns the updated Conversation with its pin attributes set.

Unpin a Conversation

To unpin a conversation, use the unpinConversation method with the same parameters. On success, the callback returns the updated Conversation with its pin attributes cleared.
A user cannot unpin a system pin (a conversation pinned globally by the app). Use isSystemPinned() to detect this case and hide the unpin action.

Fetch Pinned Conversations

The default conversations list already orders pinned conversations at the top. To fetch only pinned conversations, use the setPinnedBy() filter of the ConversationsRequestBuilder.
Starting with v5.1.0, the CallbackListener overload of `fetchNext()` is deprecated. Use `ConversationFetchListener` instead; it requires SDK 5.1.0 or later, so on 5.0.x keep using CallbackListener. With offline support off, it behaves exactly like the old callback: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, it also delivers the cached result first; the old overload keeps working but receives only the server result. See Show Cached Data.

Check if a Conversation is Pinned

Every fetched Conversation carries its pin state.

Real-time Conversation Pin Events

Register a ConversationListener to be notified when a conversation is pinned or unpinned, so your list can reorder without a refetch. Your own pin or unpin fires onConversationPinned / onConversationUnpinned on the device that performed it, just before the pinConversation() / unpinConversation() success callback, so update your UI in one of the two, not both. These callbacks also fire on the user’s other devices when a pin frame arrives there.
To stop listening, remove the listener with CometChat.removeConversationListener(listenerID).

Pin Limit

A user can pin a capped number of conversations, configurable per app. Read the cap rather than hard-coding it — it is tenant-overridable and will drift.
Both are synchronous and never throw. They return Settings.LIMIT_UNSPECIFIED (-1) when the app settings carry no value or when they are called before init() completes — show generic copy in that case rather than guessing a number. getSystemPinConversationLimit() is the separate cap for admin/global pins: system pins do not consume a user’s allowance, so the two budgets are enforced independently. When the limit is breached, the SDK surfaces the server error through onError, and the applicable limit is carried in the exception’s errorParams:

Error Handling

Feature Availability

Check whether the Pin Conversation feature is enabled for your app before showing pin actions in your UI. The method is synchronous and safe to call from the UI layer.

Offline Behaviour

With offline support enabled, fetchNext() on a setPinnedBy() request delivers a cached page first (onCachedConversations, even when empty), then the server list (onServerConversations); offline, it ends with onError with code ERROR_INTERNET_UNAVAILABLE after the cached page. onCachedConversations holds the pinned conversations the cache already knows about, in the same order.

Next Steps

Pin A Message

Highlight a message for everyone in the conversation

Save A Message

Bookmark a message privately, across conversations

Retrieve Conversations

Every filter the conversations list supports

All Real Time Listeners

Every listener the SDK exposes, in one place