Browse SDKs · Android
SDKsAndroid

Get the conversation list

Use getConversationListSplit() to retrieve the signed-in account conversation list by page.

Copy

The conversation list belongs to the signed-in account. Each ConversationInfo contains list state such as unread count, latest message, pinning, and draft.

Retrieve a page

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

        @Override
        public void onError(int code, String error) {
            // code and error describe the failure.
        }
    },
    0,
    50
);
ParameterTypeDescription
offsetlongZero-based paging offset; reset it to 0 on refresh.
countlongRequested number of conversations.

The callback returns the current List<ConversationInfo> page. Advance offset by the requested item count. A page smaller than count normally indicates the end.

Keep the list synchronized

Use OnConversationListener to receive the following callbacks when conversations are added or changed:

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

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

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

Both callbacks carry List<ConversationInfo>; update the corresponding conversation by conversationID. Once set, setOnConversationListener() receives conversation changes.