Toasty: A basic guide to the Android Studio “Toast” Feature
By: Samidh Patel
Tags: Android App Development, Flatiron School

Android Bot

When I first started programming, I came across a programming tool called Android Studio. This was based on Java, and it allows you to create Android applications, for smartphones and tablets. The screen below represents the software version you want to use in order to build your app, for example, Android 7.0 (Nougat) to Android 8.0 (Oreo). This makes sure your software is compatible with your device.

This step is very important because you want to select a version that is being used by the most amount people in the world today. Most of the software versions include the percentage of people currently using the software version on their device. This means that your apps will run on that specific software version only, so it’s better to select multiple software versions.

A very cool feature that Android Studio uses is called toasts. Is Android naming everything after food?! Toasts are pop up messages which provide feedback for a specific operation happening on your device. It gives you a notification for the current app you are using, which doesn’t take up any space on your screen.

The toasts are specific to the action being performed by the user, for example, if a person sends a message and the message doesn’t go through, they will receive a toast asking about the message not being sent. They will be able to re-send the message again after restarting the app because the user was able to understand what the problem was based on the information provided by the toast. Toasts keep everything simple and concise, less than a few words.

Here’s an example of a toast:

Some examples of toasts include “press back to exit the application” or “message failed to send”. These are some of the custom examples a toast can be used for. It doesn’t take up space on the screen, and disappears, after a few seconds.

Here is an example of the code (Java) used to create a toast for an Android application:

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

The breakdown of the code is as follows below:

Toast.makeText: This creates a new Toast object.

This creates a new Toast object. Context/getApplicationContext: Refers to the entire application itself and what processes are running within the application. This is tied to the entire lifecycle of the application, so the processes required for the app will continue running even if you close the app.

Refers to the entire application itself and what processes are running within the application. This is tied to the entire lifecycle of the application, so the processes required for the app will continue running even if you close the app. Text: Refers to what the toast will say, for example, a string “Hello User”. This can be customized to say anything you want, as long as it makes sense to the user of the application.

Refers to what the toast will say, for example, a string “Hello User”. This can be customized to say anything you want, as long as it makes sense to the user of the application. Duration: Refers to the length of time, the toast will remain on the screen.

— -Toast.LENGTH_SHORT will display a toast for a few seconds.

— -Toast.LENGTH_LONG will display a toast for a longer amount of time.

Show: Refers to the toast being displayed on the screen.

Toasts are a great way to receive instant feedback on how your app operates. It gives you a prompt that is easy to follow, even for a person who has never used an Android device. I might be biased because I switched from Apple to Android sometime in the past, but it’s one of the features that I personally love about Android.