3.5.12.3Destroying toast

The normal lifecycle is that a toast notification is destroyed when either of the following happens:

The user clicks on it

The toast reaches its expiry time (either the app's default of a few seconds, or an explicit lifespan provided when creating the toast)

There can be two exceptions to this lifespan:

The toast is given noDestroyOnClick:true in its properties. A click does not destroy the toast, and it survives until its expiry.

And/or, the toast is given a long lifespan, keeping it on screen for a long time.

In either of these circumstances, the caller may want to remove the toast manually, using Framework.DestroyToast(). For example:

// Note: no callback. DestroyToast() is fire-and-forget.

Framework.DestroyToast("1234-5678-abcd");

The ID of the toast, for passing to DestroyToast(), can be obtained in two ways:

By providing an explicit toastId in the call to CreateToast()

Using the toastId in the click callback function

For example, to display a permanent toast until the user clicks on it (replacing the automatic destruction in the event of a click):

Framework.CreateToast({

title: "Permanent…",

text: "Stays on screen until manually destroyed",

noDestroyOnClick: true,

lifespan: 999999999

}, function (ToastClickMsg) {

… some asynchronous process during which the toast remains on screen,

and then …

Framework.DestroyToast(ToastClickMsg.toastId);

});