How to use toast


//define a class level local variable first
Toast mToast;


//some time later do something like this

// Tell the user about what we did.
if (mToast != null) {
   mToast.cancel();
}
mToast = Toast.makeText(AlarmController.this, 
         R.string.repeating_unscheduled,
         Toast.LENGTH_LONG);

mToast.show();

Toast API ref

A toast is a view containing a quick little message for the user. The toast class helps you create and show those. When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved. The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.

in the previous code the "cancel" seem to be there to not show the previous message or stop showing if shown. If this is not a requirement then it doesn't need to be used.

Calls to toast seem to work even if done repeatedly in the main thread one after the other, like sending debug messages from a menu response.

Understand toast more...