Skip to main content

Lifecycle API

Lifecycle API

OnShow(Action<OnShowResult> callback)

Event called when the app transitions to the foreground. Register as a static event.

Callback Parameter (OnShowResult):

FieldTypeDescription
querystringLaunch query parameters
void OnEnable()
{
TudadaSDK.OnShow += OnAppShow;
}

void OnDisable()
{
TudadaSDK.OnShow -= OnAppShow;
}

void OnAppShow(OnShowResult result)
{
Debug.Log("App foreground");
Time.timeScale = 1;
// Resume BGM, resume game, etc.
}

OnHide(Action<OnHideResult> callback)

Event called when the app transitions to the background. Register as a static event.

Callback Parameter (OnHideResult):

FieldTypeDescription
reasonstringReason for background transition
void OnEnable()
{
TudadaSDK.OnHide += OnAppHide;
}

void OnDisable()
{
TudadaSDK.OnHide -= OnAppHide;
}

void OnAppHide(OnHideResult result)
{
Debug.Log("App background");
Time.timeScale = 0;
// Save data, pause game, etc.
}

ExitMiniProgram(onSuccess, onFail)

Exits the app.

Parameters:

ParameterTypeRequiredDescription
onSuccessAction<ExitMiniProgramResult>-Success callback
onFailAction<string>-Failure callback
TudadaSDK.Instance.ExitMiniProgram(
onSuccess: (result) => Debug.Log("Exit requested")
);

RestartMiniProgram(onSuccess, onFail)

Restarts the app.

Parameters:

ParameterTypeRequiredDescription
onSuccessAction<RestartMiniProgramResult>-Success callback
onFailAction<string>-Failure callback
TudadaSDK.Instance.RestartMiniProgram(
onSuccess: (result) => Debug.Log("Restart requested")
);