Browse SDKs · Android
Platform
SDKsAndroid

Get the conversation list

Paginate the conversation list for the authenticated user and keep it synchronized with real-time updates.

Copy

The conversation list belongs to the authenticated user. Paginate queries to avoid loading excessive data into memory at once. Each ConversationInfo record encapsulates unread counts, latest messages, pinning state, and drafts.

Code example

OpenIMClient.getInstance().conversationManager.getConversationListSplit(
    new OnBase<List<ConversationInfo>>() {
        @Override
        public void onSuccess(List<ConversationInfo> conversations) {
            // conversations contains the current page of conversations.
        }

        @Override
        public void onError(int code, String error) {
            // code and error describe the failure.
        }
    },
    0,
    50
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<List<ConversationInfo>>YesCallback delivering the asynchronous query result.
offsetlongYesZero-based paging offset; reset to 0 on initial load or pull-to-refresh.
countlongYesNumber of conversation items to fetch in this page.

Return value

The successful callback returns the current page as List<ConversationInfo>. Merge and deduplicate items using conversationID as the unique primary key. When the returned list size is less than count, the end of the conversation list has been reached. When loading the next page, increment offset by the total number of conversations fetched so far.

Keep the list synchronized

Register OnConversationListener at the application layer to receive real-time notifications when conversations are added or updated:

OnConversationListener conversationListener = new OnConversationListener() {
    @Override
    public void onNewConversation(List<ConversationInfo> conversations) {
        // conversations contains newly created conversations.
    }

    @Override
    public void onConversationChanged(List<ConversationInfo> conversations) {
        // conversations contains updated conversations.
    }
};

OpenIMClient.getInstance().conversationManager.setOnConversationListener(
    conversationListener
);

Both callbacks carry a List<ConversationInfo>. When receiving updates, iterate through the list, locate the corresponding local conversation using conversationID, merge modified fields or insert new records, and re-sort the UI list. When logging out or switching accounts, pass null or unregister callbacks to clear stale listeners.