Skip to main content

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:

FieldTypeDescription
timestampnumberEvent 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:

FieldTypeDescription
(none)--
TudadaSDK.onHide((res) => {
console.log('App moved to background');
// Pause game, save data, etc.
});

TudadaSDK.offHide();

exitMiniProgram(options)

Exits the app.

Options:

ParameterTypeRequiredDescription
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback
TudadaSDK.exitMiniProgram({
success: () => console.log('Exit request sent'),
});

restartMiniProgram(options)

Restarts the app.

Options:

ParameterTypeRequiredDescription
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback
TudadaSDK.restartMiniProgram({
success: () => console.log('Restart request sent'),
});