Event
These APIs allow the game to listen to or retrieve information about its transition between the foreground and background states.
API | Description | Context |
.onShow(cb) | Listener: Registers a callback when the Mini Game comes back to the foreground (becomes visible) from the background. | Useful for pausing/resuming game action and checking for parameters passed during re-entry. |
.offShow(cb) | Cancels the | -- |
.onHide(cb) | Listener: Registers a callback when the Mini Game is sent to the background (hidden). | Critical for saving game state and pausing resource consumption. |
.offHide(cb) | Cancels the | -- |
.getLaunchOptionsSync | Synchronous: Retrieves the parameters used when the Mini Game was cold-started (opened for the first time in the session). | Returns object containing scene (entry point) and query (URL parameters). |
.getEnterOptionsSync | Synchronous: Retrieves the parameters used for any start (cold start or hot start/return from background). | Provides consistent entry parameters regardless of the starting state. |
TTMinis.game.onShow(listener)
Registers a listener for the event that is called when the mini game returns to the foreground.
Parameters
Field | Type | Description | Required |
|
| The listener function for the mini game returning to the foreground | Yes |
Listener callback parameters
Field | Type | Description |
|
| Scene value |
|
| Query parameters |
Example
TTMinis.game.onShow((result) => {
let query = result.query;
// do something when mini game shows
});TTMinis.game.offShow(listener)
Removes the listener for the mini game returning to the foreground event.
Parameters
Field | Type | Description | Required |
|
| The same listener function that was passed to | Yes |
Example
const listener = function (res) { console.log(res) }
TTMinis.game.onShow(listener)
TTMinis.game.offShow(listener) // Must pass the same function object used during registrationTTMinis.game.onHide(listener)
Registers a listener for the event that is called when the mini game is hidden to the background.
Parameters
Field | Type | Description | Required |
|
| The listener function for the mini game being hidden to the background | Yes |
Example
TTMinis.game.onHide(() => {
// do something when mini game hides
});TTMinis.game.offHide(listener)
Removes the listener for the mini game being hidden to the background event.
Parameters
Field | Type | Description | Required |
|
| The same listener function that was passed to | Yes |
Example
const listener = function (res) { console.log(res) }
TTMinis.game.onHide(listener)
TTMinis.game.offHide(listener) // Must pass the same function object used during registrationTTMinis.game.getLaunchOptionsSync()
Gets the launch parameters of the mini game during cold start synchronously.
Returns
Launch parameters.
Field | Type | Description |
|
| The scene value used to launch the mini game |
|
| The query parameters used to launch the mini game |
Scene values
Scene | Description |
| Entered by scanning a QR code |
| Entered by search |
| Entered via anchor mount |
| Entered via sidebar re-visit entry |
| Entered via advertisement |
| Entered via desktop shortcut |
| Entered via direct message sharing |
| Entered via minis link |
Example
const launchOptions = TTMinis.game.getLaunchOptionsSync()TTMinis.game.getEnterOptionsSync()
Gets the enter parameters of the mini game (including both cold start and warm start) synchronously.
Returns
Launch parameters.
Field | Type | Description |
|
| The scene value used to launch the mini game |
|
| The query parameters used to launch the mini game |
Example
const enterOptions = TTMinis.game.getEnterOptionsSync()