Thursday, February 05, 2009

 

Minimal code to display a Toast message in Google Android

Toast is a widget to display an informational message to a user whilst they may well be doing something else. I find it useful for debugging on a real device to tell me something internal to the application has been fired. Afterwards I can just strip such things out of the build.

// show the frost pist message using the Toast widget
Toast toast = Toast.makeText(context, "Woo hoo, toast", Toast.LENGTH_LONG);
toast.show();


I find the context is normally part of the method signature.
Toast.LENGTH_LONG keeps the message up for a few seconds.

There is a Toast.LENGTH_SHORT if you don't want the message to hang about for too long.

Labels:


Comments: Post a Comment

Subscribe to Post Comments [Atom]



Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]