Create a Toast

Introduction
Android has a simple notification system called Toast. Toasts are popups that can display short messages. In Material Design, it's now common to use Snackbars as a replacement for Toasts. If you want to learn how to make a Snackbar, follow the Create a Snackbar tutorial.

In this tutorial, you will learn how to create a Toast and how to make it be displayed for the user.

Importing
Import the following class:

Creating a Toast
Create a new Toast by calling the method Toast.makeText.

The first parameter is the context of the view. The second parameter is the text to be displayed. And the third parameter is the amount of time the Toast is supposed to stay visible. It has three options:

After you created the Toast, you must call a method to show it. It will stay up for as long as you setted up as the LENGTH parameter.

You don't need to create a new Toast everytime you want to display a message. You can create it once and call show everytime you want to display it. That will save the time and memory necessary to allocate a new Object.

By now, your code should look like this:

Conclusion
When you finish, your activity should have a working Toast that can be called anytime to display a message.

You now know how to create a Toast and how to display it.

Next Steps

 * Create a Snackbar