SDKsAndroid
Load older messages
Use getAdvancedHistoryMessageList to load conversation history by page.
Retrieve historical messages backwards in time (towards older messages) within a specified conversation. For the initial page load, pass null for startMsg. For subsequent pages, pass the oldest message from the previous batch as the new startMsg.
Code example
String conversationID = "si_user_a_user_b";
Message startMessage = null; // Pass null for the initial page, or the oldest message from the last batch
int count = 20;
OpenIMClient.getInstance().messageManager.getAdvancedHistoryMessageList(
new OnBase<AdvancedMessage>() {
@Override
public void onSuccess(AdvancedMessage result) {
List<Message> messages = result.getMessageList();
boolean reachedBeginning = result.isEnd();
// Prepend deduplicated messages to the top of the chat timeline using clientMsgID
}
@Override
public void onError(int code, String error) {
// Failed to load historical messages
}
},
conversationID,
startMessage,
count,
ViewType.History
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<AdvancedMessage> | Yes | Callback handler for the asynchronous request. |
conversationID | String | Yes | Globally unique ID of the target conversation. |
startMsg | Message | No | Anchor message for pagination. Pass null for initial load, or the oldest message from the preceding batch. |
count | int | Yes | Maximum number of messages to retrieve in this batch. |
viewType | ViewType | Yes | View mode enum. Pass ViewType.History for regular history loads. |
Return value
Upon success, onSuccess returns an AdvancedMessage object:
| Field | Description |
|---|---|
messageList | List of retrieved messages (List<Message>) for the current page. |
isEnd | Indicates whether the beginning of history has been reached (true means no earlier messages exist, false means more can be loaded). |
errCode | Result error code. |
errMsg | Result error description. |
State changes after the call
- Snapshot retrieval: This is a read-only query that loads point-in-time message records without emitting new-message events.
- UI integration: Prepend messages to the chat view, deduplicating records using
clientMsgID.
Was this page helpful?