DEV Community

Sunny k.thakur
Sunny k.thakur

Posted on

Toast message in android

Image descriptionHow to write Toast message in Android I just started learning Android development
what is the right way to write Toast message in java Android

Top comments (3)

Collapse
 
dibasdauliya profile image
Dibas Dauliya • Edited

You haven't given context in your code. Try this:

Toast.makeText(MainActivity.this, "Toast message", Toast.LENGTH_SHORT).show();
Enter fullscreen mode Exit fullscreen mode

If you want to make your Toast appear for a long time then replace LENGTH_SHORT with LENGTH_LONG.

Read more about Toast and its alternatives at developer.android.com/guide/topics....

Collapse
 
z80asmcoder profile image
z80AsmCoder

You can also use getApplicationContext() instead of MainActivity.this

Collapse
 
sunnythakr profile image
Sunny k.thakur

Thanks Dibas