Sign up

cloud messaging

What Is a Toast Message, and How Do You Use It?

Angela Stringfellow

Last updated on

User experience plays a huge role in the success of any software application, and many believe user experience designers deal with the visual aspects of software applications. This is not true. The task of a user experience designer is to make the application easier and more convenient to use from the perspective of the user. This includes the layout of the application, how things are organized, process flow, and a host of other factors that impact how users interact with the application. User experience designers use Toast messages to deliver a superior experience while using the application.

What Are Toast Messages?

Toast messages help to deliver simple feedback to the user. They most often follow an action performed by a user and provide information regarding the success or failure of that action. Toast messages are informative, have a lifespan of just a few seconds and take up a very small portion of the screen.

Toast messages ensure that the use of the application is not interrupted while providing necessary information for the user. They have no notification sounds associated with them and don’t appear in the notification centers on any platform, but appear at the bottom of the viewport by default. (However, this can be modified by developers.)

Toast messages were first available for Android applications. Now most platforms natively support toast messages, including both Android and iOS. Common frameworks used to develop web applications, such as react-native and Ajax, also support toast messages.

An Example

Gmail is a popular email application used by billions of users around the globe. It extensively uses toast messages to deliver short messages to users for a brief period of time and is probably the most popular application to do so.

When you send messages from the Gmail application, a toast message appears saying “Sending…”. Once the email is sent, the Toast message changes to “Message sent.” The image below is a screen grab of a Toast message in the Gmail Android application. Gmail has similar Toast messages for messages moved to trash, archived or moved to another folder. This gives the user relevant information with respect to actions they performed within the application. The user can continue using the application without minding the Toast message.

The Gmail application also supports limited actions within Toast messages. A Toast message appears when deleting emails from the Gmail browser interface. The message says “Conversation moved to Trash”. It is accompanied by a button (UNDO) that the user can tap to revert the deletion. The user can choose to tap the button or ignore the Toast message altogether.

How To Use Toast Messages

The way to display Toast messages using react-native for Android is extensively covered in this article. Below, we’ll discuss how to use Toast messages in a pure Android development environment. Android supports both Kotlin and Java for coding, and we will review the code for both.

To initiate a Toast object, the makeText() method is used. Here you should mention the application context, content of the message, and the duration of the toast message. To display the Toast message, you can use the method show(). An example code is given below.

Kotlin:

val text = "Example toast message."
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(applicationContext, text, duration)
toast.show()

Java:

Context context = getApplicationContext();
CharSequence text = "Example toast message.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

There’s no need to create the Toast message and display it using two separate lines of code as they can be cobbled together for brevity as shown below. The same code can be used for both Java and Kotlin.

Toast.makeText(context, text, duration).show()

Wrapping Up

Toast messages are useful for displaying messages for a very brief duration of time and can give users important information without hindering the use of the application. They are available on almost all software platforms but are natively supported on Android, where they can be implemented using just a few lines of code.

The trouble with Toast messages is that users will not be able to view them once the message disappears. You can, however, add an inbox functionality that captures Toast messages and allows users to view messages later. You can also integrate notification messages and other transactional messages into the inbox. This gives the flexibility for users to access any message at any time.

MagicBell is the best tool to implement an inbox with your application. It integrates easily with all code environments and works seamlessly across various platforms like mobile applications and web applications.