Browse SDKs · Android
SDKsAndroid

Open a conversation

Use getOneConversation() to retrieve one Android conversation by user or group.

Copy

Use getOneConversation() when opening a chat from a contact, user profile, or group profile. Pass the peer user ID for a one-to-one chat and the group ID for a group chat; do not construct ConversationInfo locally when no messages exist yet.

OpenIMClient.getInstance().conversationManager.getOneConversation(
    new OnBase<ConversationInfo>() {
        @Override
        public void onSuccess(ConversationInfo conversation) {
            openChatPage(conversation);
        }

        @Override
        public void onError(int code, String error) {
            recordConversationOpenFailure(code, error);
        }
    },
    targetUserID,
    ConversationType.SINGLE_CHAT
);

sourceId is the peer userID for a one-to-one chat and groupID for a group chat. Use ConversationType.GROUP_CHAT or ConversationType.SUPER_GROUP_CHAT for a group according to its type.

The callback returns ConversationInfo. This query does not trigger a conversation listener; Get the conversation list merges later changes by conversationID.