startGame
Start a Game (by Game ID)
startGame starts a game by its ID. Attach the view provided by onGameViewCreated to your page to display the loading UI and game. Use language to select the loading view's game name and icon.
Prerequisites
Call SUDOP.initSDK and SUDOP.auth successfully before starting a game. Call startGame on the UI thread and prepare a view container first.
Method Declaration
// Start a game without specifying a language
public static SUDOPGameTask startGame(String gameId, SUDOPStartGameListener listener);
// Start a game with an optional language
public static SUDOPGameTask startGame(String gameId, String language, SUDOPStartGameListener listener);The original overload remains available and is equivalent to passing null for language. The returned SUDOPGameTask manages the game lifecycle.
Parameters
| Parameter | Type | Description |
|---|---|---|
| gameId | String | Required. The unique identifier of the game to start. |
| language | String | Optional BCP 47 language tag, such as zh-CN or en-US. Selects the loading view's game name and icon. If null or empty, the loading view uses the system language. |
| listener | SUDOPStartGameListener | Required. Launch process listener. |
SUDOPStartGameListener
void onGameViewCreated(View view): The container view has been created. Add it to your layout to display the loading UI and game.void onGamePkgDecrypt(GamePkgDecryptHandle handle, String filePath): Game package decryption callback for applicable file or URL loading flows.void onCreated(SUDRTGameHandle gameHandle, SUDOPGameInfo gameInfo): The game instance has been created. Provides the instance handle and game information.void onSuccess(String gameId, SUDRTGameHandle gameHandle): The game started successfully.void onProgress(int progress): Loading progress, from 0 to 100.void onFailure(int retCode, String retMsg): The game failed to start.
GamePkgDecryptHandle
void success(String decryptedFilePath, boolean isDeleteFile): Decryption succeeded. Pass the decrypted file path and whether to delete it after the game finishes loading.void fail(int retCode, String retMsg): Decryption failed. Pass the error code and description.
Loading View Language Selection
The loading view displays the game name and icon according to these rules:
- If
languageis non-empty, the loading view uses that exact language tag. If it isnullor empty, it uses the system language. - The game name uses the localized
game_namevalue, falling back togame_name["default"]if the selected value is missing or empty. - The icon uses the localized
iconvalue first, thenicon["default"]if the selected value is missing or empty. - If neither icon value is available, load the legacy
game_iconURL. If all URLs are empty, no icon is loaded.
The legacy icon fallback applies when a URL cannot be obtained from icon; it is not a fallback for image download failures. Language keys are matched exactly, without adding a regional-to-base-language fallback. These rules control the loading view's game name and icon.
Example Code
Assume container is the page's prepared FrameLayout. Run this code on the UI thread after initialization and authentication succeed.
String language = "zh-CN";
SUDOPGameTask gameTask = SUDOP.startGame("game_101", language, new SUDOPStartGameListener() {
@Override
public void onGameViewCreated(View view) {
container.addView(view, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
}
@Override
public void onGamePkgDecrypt(GamePkgDecryptHandle handle, String filePath) {
// No custom decryption is needed for this game-ID launch example.
}
@Override
public void onCreated(SUDRTGameHandle gameHandle, SUDOPGameInfo gameInfo) {
}
@Override
public void onSuccess(String gameId, SUDRTGameHandle gameHandle) {
// The game has started; its view was already attached in onGameViewCreated.
}
@Override
public void onProgress(int progress) {
}
@Override
public void onFailure(int retCode, String retMsg) {
Log.e("SUDOP", "Failed to start game: " + retCode + ", " + retMsg);
}
});Pass your app's selected BCP 47 language tag, using the same value as getGameInformation.
Notes
- Task retention: Retain the returned
SUDOPGameTaskand calldestroy()when the page is destroyed. Check fornullbefore using the task, because invalid arguments can causestartGameto returnnull. - View attachment: Attach the view once in
onGameViewCreated; do not add it again inonSuccess. - Single instance: It is recommended to run only one game instance at a time.
