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 ...

Get Learning AndEngine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.