Toast

The Toast object contains functions for displaying toast notifications.

The functionality of this object allows the developer to display system toast notifications within their WebWorks application.


Device showing a toast.         Device showing a toast with an undo button.

Learning Resources:

Sample - Using Toast Sample that demonstrates how to use the BlackBerry Toast API [BlackBerry on GitHub].

Supported Platform(s)

- BlackBerry 10
View Supported Platform Table
APIBB5.0BB6.0BB7.0PB1.0PB2.0BB10Ripple
blackberry.ui.toast.show           Y 

Configuration Document Settings

To use all of the API described for this object, you must ensure the following settings are in your configuration document:

You must declare the feature element(s) below in your configuration document:

Feature IDBB5.0BB6.0BB7.0PB1.0PB2.0BB10Ripple
<feature id="blackberry.ui.toast" />           Y 

Permission Elements (PlayBook and BlackBerry 10+)
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application.

Functions

Functions

static Number blackberry.ui.toast.show (message : String, [options : Object])


Displays a toast notification.


Supported Platforms
 - BlackBerry 10


Parameters
message Message to be displayed in the toast.
options options object that specifies the buttonText, and callback handlers that should be used by the toast

buttonText: parameter that specifies the label for the button within the toast.
buttonCallback: callback for receiving the button event when the user selects the toast button.
dismissCallback: callback for receiving an event when the toast dismisses either through the toast's timeout or when the button is selected.
timeout: timeout value that can be used to extend the toast for as long as the user desires. The value specified is parsed in milliseconds.

Return:

A numeric ID to reference this toast by.



Code Example:
<script type="text/javascript">

function showCustomToast() {
   var message = "This is my toast!",
       buttonText = "Click Me",
       toastId,
       onButtonSelected = function () {
          console.log('Button was clicked for toast: ' + toastId);
       },
       onToastDismissed = function () {
          console.log('Toast disappeared: ' + toastId);
       },
       options = {
         buttonText : buttonText,
         dismissCallback : onToastDismissed,
         buttonCallback : onButtonSelected
       };

   toastId = blackberry.ui.toast.show(message, options);
}

function showCustomToastWithTimeout() {
   var message = "This is my toast!",
       buttonText = "Click Me",
       toastId,
       onButtonSelected = function () {
          console.log('Button was clicked for toast: ' + toastId);
       },
       onToastDismissed = function () {
          console.log('Toast disappeared: ' + toastId);
       },
       options = {
         buttonText : buttonText,
         dissmissCallback : onToastDismissed,
         buttonCallback : onButtonSelected,
         timeout : 10000
       };

   toastId = blackberry.ui.toast.show(message, options);
}
</script>
Documentation generated by JsDoc Toolkit 2.4.0 on Mon Feb 11 2013 14:51:11 GMT-0500 (EST)