The Toast
is a noninteractive, auto disposable view used to display a short message for a specified period of time and disposes itself. Android recommends that you use Toast
only to notify the user, where the user's attention is not mandate. For any such notification that requires the user's attention or interaction, consider using dialog.
Creating a Toast
is simple, all you have to do is to call the MakeText()
static method by passing three parameters: the application context, message to be shown, and the time duration for the Toast
to be shown. The time duration is a non-negative integer value in milliseconds, but it is recommended that you use the standard Long
and Short
constants defined in the ToastLength
enum. The MakeText()
method initializes the Toast with the given properties and returns a Toast
instance on which we can call the Show()
method to display Toast
.
In the preceding code snippet, we are displaying the Toast
message when the device is offline. The following code depicts...