create
Create the Mini-Game Runtime Environment
create() is the first action command in the mini-game startup flow. Before calling this method, you must have already configured the startup options (setGameStartOptions). After executing this method, the Runtime initializes the underlying engine instance, prepares the JS runtime environment, and allocates the necessary system resources.
Method Declaration
java
/**
* Creates the mini-game runtime environment.
* On success, the mini-game instance enters the `WAITING` state.
* The runtime environment can only be created correctly when the startup options are set correctly and no runtime environment currently exists.
*/
void create();Runtime Behavior and State Transitions
1. Preconditions
- You must first call
setGameStartOptionsto set a validappId. - The current state must be
GAME_STATE_UNAVAILABLE.
2. Execution Process
- The SDK checks whether the local game resource package is intact.
- Initializes the rendering surface (Surface/Texture).
- Starts the built-in JS virtual machine (such as V8 or JSC).
3. Result
- On success, the state changes to
GAME_STATE_WAITING. - On failure (e.g., out of memory, package verification failure), you are notified via the
GameStateChangeListener.onFailurecallback.
Example Code: Standard Initialization Sequence
java
// 1. Set the required options
Bundle options = new Bundle();
gameHandle.setGameStartOptions("my_game_123", options);
// 2. Listen for state feedback
gameHandle.setGameStateListener(new SUDRTGameHandle.GameStateChangeListener() {
@Override
public void onStateChanged(int fromState, int toState) {
if (toState == SUDRTGameHandle.GAME_STATE_WAITING) {
// The environment is ready; you can start the script next.
Log.i("SUDOP", "Environment created. Ready to start().");
gameHandle.start("{}");
}
}
// ... other callbacks omitted
});
// 3. Trigger creation
gameHandle.create();Notes
- Idempotency restriction: If the game is already in the
WAITING,RUNNING, orPLAYINGstate, repeated calls tocreate()are usually ignored or return an error. - Resource usage: After
create(), the JS engine consumes a certain amount of memory. If the user stays on the loading page for a long time without entering the game, consider whether to calldestroy()to release resources based on your business logic. - View retrieval: Usually, after
create()succeeds, you can obtain theViewobject for display viagetGameView()and add it to your layout.
