Load Game by GameId
This document describes how to launch a game via GameId and load the game view into an application page.
Overview
Through the SUDOP.startGame interface, you can launch a game based on the game's unique identifier gameId.
Add the view to your page's UI container in onGameViewCreated to display the loading UI and game. Track loading progress through onProgress, and handle the launch result through onSuccess or onFailure.
Full Process
Before launching the game, you must complete the following steps in order:
- Initialize the SDK (
initSDK) - User authentication (
auth) - Launch the game (
startGame)
Example Code
Call this code on the UI thread. container is an initialized view container, and gameTask is a SUDOPGameTask field retained by the page. The example passes a language tag using the same approach as getGameInformation.
String language = "zh-CN";
SUDOP.initSDK(context, "Your appId", "Your appKey", new SUDOPInitSDKListener() {
@Override
public void onSuccess() {
SUDOP.auth("Your user signature", new SUDOPAuthListener() {
@Override
public void onSuccess() {
gameTask = SUDOP.startGame("You need to load the game id", language, new SUDOPStartGameListener() {
@Override
public void onGameViewCreated(View view) {
// Add the loading/game view to the prepared container.
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) {
// Game instance created; you can set parameters or inject interaction objects here
}
@Override
public void onSuccess(String gameId, SUDRTGameHandle gameHandle) {
// The game started; the view was attached in onGameViewCreated.
}
@Override
public void onProgress(int progress) {
// Loading progress: 0 to 100.
}
@Override
public void onFailure(int retCode, String retMsg) {
// Game loading failed
}
});
}
@Override
public void onFailure(int retCode, String retMsg) {
// Authentication failed
}
});
}
@Override
public void onFailure(int retCode, String retMsg) {
// SDK initialization failed
}
});Core Interface
startGame
public static SUDOPGameTask startGame(String gameId, SUDOPStartGameListener listener);
public static SUDOPGameTask startGame(String gameId, String language, SUDOPStartGameListener listener);Parameters
| Parameter | Type | Description |
|---|---|---|
| gameId | String | Required, unique game identifier |
| language | String | Optional BCP 47 language tag, such as zh-CN or en-US |
| listener | SUDOPStartGameListener | Required, launch process listener |
Language and Loading UI
Use language to select the loading view's game name and icon. The original overload remains available and is equivalent to passing null for language.
The loading view displays the game name and icon for the exact language tag specified by language. If it is null or empty, the loading view uses the system language. Missing or empty values fall back to the map's default entry. If neither the selected icon nor icon["default"] has a value, the SDK loads the legacy game_icon URL. This fallback handles missing URLs, not image download failures.
Pass your app's selected BCP 47 language tag, using the same value as getGameInformation. See startGame for full parameter and loading view behavior.
Callbacks
SUDOPStartGameListener
void onGameViewCreated(View view)Add this view 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)Game instance created Configure the game orientation and register the callbacks needed by your app.
void onSuccess(String gameId, SUDRTGameHandle gameHandle)Game started successfullyThe game view has already been attached in
onGameViewCreated.
void onProgress(int progress)Loading progress, from 0 to 100.
void onFailure(int retCode, String retMsg)Game startup failedCommon causes:
- Incorrect gameId
- Network exception
- Authentication failure
GamePkgDecryptHandle
void success(String decryptedFilePath, boolean isDeleteFile)Decryption succeededvoid fail(int retCode, String retMsg)Decryption failed
Launch Flow
After calling startGame:
- Attach the view received in
onGameViewCreatedto your page. - The loading view displays the game name and icon using the language selection rules above.
- Use
onProgressto track loading progress. - Handle launch success in
onSuccessor failure inonFailure.
UI Integration
You need to prepare a container, e.g.:
FrameLayout container;In onGameViewCreated(View view):
container.addView(view);Notes
1. Initialization and Authentication Must Be Completed
The order cannot be wrong:
initSDK → auth → startGame2. You Must Hold the GameTask
gameTask = SUDOP.startGame(gameId, language, listener);When the page is destroyed:
if (gameTask != null) {
gameTask.destroy();
}3. Single Instance Running
It is recommended to run only one game instance at a time.
4. UI Thread Safety
Call startGame on the UI thread. onGameViewCreated is invoked during startup; add the view to the container in that callback.
Summary
Loading a game by gameId = call startGame → attach view in onGameViewCreated → onSuccess confirms startupThe code example above is for Android; iOS follows the same process. For details, see: iOS API
