O'Reilly logo

Learning AndEngine by Martin Varga

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with toasts

Another way to output text on the screen is using toasts. A toast is a simple message widget that can provide feedback about an operation in progress. It's a core Android widget, not an AndEngine component, but we can nevertheless use it in our game.

The easiest way to show a toast is to use a static method provided by the Toast class. In a general Android app, we can simply call this as follows:

Toast.makeText(activity, "Hello World", Toast.LENGTH_LONG).show();

We can also call a toast inside the activity itself. This can be done as follows:

Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show();

The makeText() method creates the Toast object. It takes three parameters: the context (activity), the text to show, and the length ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required