Toast In Android Studio - FreeCodeBlog

Last updated: May 01, 2022


What is toast in android studio: 

Toast is nothing but a feedback or a simple pop up message when an operation performed in android studio. It is one of most useful feature to the developer to check any kind of function or onclicklistener is Working properly or not. Before write a thousands line of code we have to check at first that the block of the method are working properly so we can do that by using a toast in android studio. 
Or if anywhere it required a message to be shown or we want to just set a text which will display for a few short of time period then we can use the feature of toast in android studio. So it basically contains a quick message and disappeares after Sometimes.

How to use:
Alright, Let's see the syntax of toast in android studio and how we can use this in our android project:


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


Toast.makeText() makes and instance of Toast class. And it takes 3 values as its parameter. Those are context, text and duration.

At first context require the current activity name  in which we are working so we can put it like MainActivity.class or we can pass "this" as the context or we can use getApplicationContext() method to get the context automatically. 


After that we have to put the message within the quotes like "welcome!" which we want to show when the toast triggered. 


At last it requires duration how long it display to user. There are 2 types of duration available Toast.LENGTH_SHORT for show the message short period of time.

Toast.LENGTH_LONG will show a little longer than short.

Just use those as per your requirements.


And finally just use show() method at the last of the toast to display the toast in android studio.

After filling all the data it will show like: 


 Toast.makeText(getApplicationContext(),"welcome to freecodeblog",Toast.LENGTH_SHORT).show(); 


So that's all about toast in android studio.
-Happy coding :)

Post Tags
Post Writer
Rabbi Islam (@rabbi2437)

My name is Rabbi Islam. I'm a Java Programmer. I live in Bangladesh and I love to write tutorials that can help to other programmer.

Related Posts
Inheritance In Java Object Oriented Programming (Oop) With Example.

Inheritance is an important part in java object oriented programming (OOP). When we need to use all the property, method, and behavior of a class i... Read More

Jdk Installation Steps For Java And Android Studio In Windows 10

JDK (Java Development Kit) creates an environment for user to execute java programs. So basically if you want to run your java program, JDK has to... Read More