DEV Community

Discussion on: Toast message in android

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
 
sunnythakr profile image
Sunny k.thakur

Thanks Dibas

Collapse
 
z80asmcoder profile image
z80AsmCoder

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