preLoadGame
Pre-load a Game (by Game ID)
The preLoadGame method goes a step further than pre-download. It not only ensures the game resources are downloaded locally, but also completes the runtime environment initialization, script engine loading, and first-screen resource decoding in advance.
This interface is suitable for the "game admission" stage (for example, when the user has tapped the game entry but has not yet tapped "Start"). It significantly shortens the wait between the user tapping "Start" and seeing the game screen.
Method Declaration
/**
* Pre-load a game by game ID
*
* @param gameID gameID
* @param listener Pre-load status listener
* @return SUDOPGameTask Task handle, used to manage or destroy the pre-load task
*/
public static SUDOPGameTask preLoadGame(String gameID, SUDOPPreLoadGameListener listener);Parameters
Specifies the pre-load target:
| Field | Type | Description |
|---|---|---|
| gameId | String | Required. The unique identifier of the game to pre-load. |
SUDOPPreLoadGameListener
Receives the pre-load result callback:
void onSuccess(String gameId, SUDRTGameHandleProvider provider): Pre-load completed.gameId: The game identifier.provider: Callprovider.getGameHandle()to obtain the game instance handle.void onFailure(int retCode, String retMsg): Pre-load failed. Possible causes include insufficient memory, a resource loading error, or an environment conflict.
Runtime Behavior
- Resource verification: First checks whether the local resources are complete; if any are missing, silent download is triggered automatically.
- Environment warm-up: Starts the Runtime container required by the game and pre-executes the base scripts.
- Handle generation: Creates the
SUDRTGameHandlein advance. When the user actually starts the game, the View can be mounted quickly through this handle. - State lock: After pre-load succeeds, the game instance enters a "ready to mount" state, waiting for the formal launch command.
Example Code
// Perform pre-load
SUDOPGameTask preLoadTask = SUDOP.preLoadGame("game_101", new SUDOPPreLoadGameListener() {
@Override
public void onSuccess(String gameId, SUDRTGameHandleProvider provider) {
SUDRTGameHandle handle = provider.getGameHandle();
// Pre-load succeeded; cache the handle and use it directly when the user taps Start
Log.i("SUDOP", "Pre-load success. Game is ready to show.");
}
@Override
public void onFailure(int retCode, String retMsg) {
// Pre-load failed
Log.e("SUDOP", "Pre-load failed: " + retMsg);
}
});
// If the user leaves the page, cancel the pre-load to release memory
// preLoadTask.destroy();Notes
- Memory consumption: Unlike "pre-download," which only uses disk, "pre-load" consumes a certain amount of CPU and memory resources. Avoid pre-loading multiple games at the same time.
- Prerequisites: Before calling, make sure
initSDKhas succeeded, andauthauthentication is usually required. - Lifecycle synchronization: If the game is not started for a long time after a successful pre-load, call
task.destroy()to release resources and prevent out-of-memory issues.
The success callback returns SUDRTGameHandleProvider. Call provider.getGameHandle() to obtain the SUDRTGameHandle.
