This module provides the game launch acceleration capability.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.GraphicsGame.LaunchAcceleration
Since: 6.0.0(20)
isLaunchMirrorEnabled(): boolean
Checks whether the memory snapshot function is enabled for the game.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.GraphicsGame.LaunchAcceleration
Since: 6.0.0(20)
Return value
| Type | Description |
|---|---|
| boolean | The system determines whether to enable the memory snapshot function by considering the game's activity level, the number of existing memory snapshots, and the amount of memory swapped out to disk for the current day on the current device. - true: The memory snapshot function is enabled. The game switches to a specific scene (the game sign-in screen is recommended) and the system automatically creates a memory snapshot before the game exits. It takes about 4 seconds to create a memory snapshot. - false: The memory snapshot function is disabled. When a user exits the game, the system will directly terminate the game process. The default value is false. |
Example
import { launchAcceleration } from '@kit.GraphicsAccelerateKit';
onWindowStageWillDestroy(): void {
// Check whether the memory snapshot function is enabled for the current game.
let enable = launchAcceleration.isLaunchMirrorEnabled()
if (enable) {
// Code logic for scene switching.
}
} completeGamePrelaunch(context: common.UIAbilityContext): Promise<void>
Notifies the system that the pre-start of the current game is complete. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.GraphicsGame.LaunchAcceleration
Since: 26.0.0
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | UIAbility context. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 1019400001 | Service error. 1. Connect to system service failed; 2.System service failed to communicate with dependency module. |
| 1019400002 | The app is not in a preloading state. |
| 1019400401 | Parameter error. |
Example
import { UIAbility } from '@kit.AbilityKit';
import { launchAcceleration } from '@kit.GraphicsAccelerateKit';
export default class EntryAbility extends UIAbility {
async completeGamePrelaunch() {
try {
await launchAcceleration.completeGamePrelaunch(this.context);
} catch (err) {
console.error(`completeGamePrelaunch failed, code is ${err.code}, message is ${err.message}`);
}
}
} terminateGamePrelaunch(context: common.UIAbilityContext): Promise<void>
Instructs the system to exit the current game pre-start process. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.GraphicsGame.LaunchAcceleration
Since: 26.0.0
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | UIAbility context. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 1019400001 | Service error. 1. Connect to system service failed; 2.System service failed to communicate with dependency module. |
| 1019400002 | The app is not in a preloading state. |
| 1019400401 | Parameter error. |
Example
import { UIAbility } from '@kit.AbilityKit';
import { launchAcceleration } from '@kit.GraphicsAccelerateKit';
export default class EntryAbility extends UIAbility {
async terminateGamePrelaunch() {
try {
await launchAcceleration.terminateGamePrelaunch(this.context);
} catch (err) {
console.error(`terminateGamePrelaunch failed, code is ${err.code}, message is ${err.message}`);
}
}
}