Lifecycle API
Lifecycle API
onShow(callback) / offShow(callback?)
Registers/unregisters an event listener for when the app transitions to the foreground. When offShow is called without a callback, all listeners are removed.
Callback Parameters:
| Field | Type | Description |
|---|---|---|
timestamp | number | Event timestamp |
TudadaSDK.onShow((res) => {
console.log('App shown, timestamp:', res.timestamp);
// Resume game, play BGM, etc.
});
// Remove specific callback
TudadaSDK.offShow(myCallback);
// Remove all callbacks
TudadaSDK.offShow();
onHide(callback) / offHide(callback?)
Registers/unregisters an event listener for when the app transitions to the background. When offHide is called without a callback, all listeners are removed.
Callback Parameters:
| Field | Type | Description |
|---|---|---|
| (none) | - | - |
TudadaSDK.onHide((res) => {
console.log('App moved to background');
// Pause game, save data, etc.
});
TudadaSDK.offHide();
exitMiniProgram(options)
Exits the app.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
TudadaSDK.exitMiniProgram({
success: () => console.log('Exit request sent'),
});
restartMiniProgram(options)
Restarts the app.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
TudadaSDK.restartMiniProgram({
success: () => console.log('Restart request sent'),
});