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.
}

OnPlatformEvent(Action<PlatformEventResult> callback)​

A custom event the platform (host) delivers to the running game. Register it as a static event. Data available at launch comes from GetLaunchOptions(); data that arrives while the game is running comes through this event. Which name/data values are sent is agreed with your platform contact. No production host currently sends any event (the channel is reserved for future use); data delivered at launch, such as an invite code, comes from GetLaunchOptions().

Events that arrive while there is no subscriber are buffered (up to 32) and delivered in order on the next subscription.

Callback Parameters (PlatformEventResult):

FieldTypeDescription
namestringEvent name — branch on this value
dataJsonstringEvent data as a JSON string ("{}" if none) — parse it into your own structure
timestamplongEvent time (epoch ms)
[System.Serializable]
class PromoEvent { public string promoId; }

void OnEnable()
{
TudadaSDK.OnPlatformEvent += OnPlatform;
}

void OnDisable()
{
TudadaSDK.OnPlatformEvent -= OnPlatform;
}

void OnPlatform(PlatformEventResult e)
{
if (e.name == "promo.open")
{
var promo = JsonUtility.FromJson<PromoEvent>(e.dataJson);
OpenPromotion(promo.promoId);
}
}

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")
);