Skip to content

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 ​

java
// 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 ​

ParameterTypeDescription
gameIdStringRequired. The unique identifier of the game to start.
languageStringOptional 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.
listenerSUDOPStartGameListenerRequired. 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:

  1. If language is non-empty, the loading view uses that exact language tag. If it is null or empty, it uses the system language.
  2. The game name uses the localized game_name value, falling back to game_name["default"] if the selected value is missing or empty.
  3. The icon uses the localized icon value first, then icon["default"] if the selected value is missing or empty.
  4. If neither icon value is available, load the legacy game_icon URL. 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.

java
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 SUDOPGameTask and call destroy() when the page is destroyed. Check for null before using the task, because invalid arguments can cause startGame to return null.
  • View attachment: Attach the view once in onGameViewCreated; do not add it again in onSuccess.
  • Single instance: It is recommended to run only one game instance at a time.