ANDROID CODE SNIPPET : HOW TO SHOW ANDROID TOAST

While developing applications for Android devices, some time we required to show a quick message or warning and it should go automatically in specified time.
For that there is widget class available ‘Toast’ in Android library.

Here I have illustrated simple code snippet to show Toast message.

Importing Class:
[as3]
import android.widget.Toast;
import android.content.Context;
[/as3]

Code Implementation:
[as3]
// Define all input variable and assign values
Context context = getApplicationContext();
String message = “Some text message here”;
int duration = Toast.LENGTH_SHORT;

// Set all required inputs
Toast toast = Toast.makeText(context, message, duration);

// Display toast on screen
toast.show();
[/as3]

Enjoy …. 🙂

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *