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):
| Field | Type | Description |
|---|---|---|
query | string | Launch 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):
| Field | Type | Description |
|---|---|---|
reason | string | Reason 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<ExitMiniProgramResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.ExitMiniProgram(
onSuccess: (result) => Debug.Log("Exit requested")
);
RestartMiniProgram(onSuccess, onFail)
Restarts the app.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<RestartMiniProgramResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.RestartMiniProgram(
onSuccess: (result) => Debug.Log("Restart requested")
);