Android Utililty Methods Toast Create

List of utility methods to do Toast Create

Description

The list of methods to do Toast Create are organized into topic(s).

Method

voidshowToast(String text, Context context)
Displays a text message via the toast notification system.
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
voidshowToast(final Context context, String text)
show Toast
if (null == context) {
    return;
if (Looper.myLooper() != Looper.getMainLooper()) {
    if (handler == null) {
        handler = new Handler(Looper.getMainLooper()) {
            @Override
            public void handleMessage(Message msg) {
...
voidshowToast(final Context context, final String message)
show Toast
final Toast makeText = Toast.makeText(context, message,
        Toast.LENGTH_LONG);
makeText.setGravity(Gravity.TOP, 0, 0);
makeText.show();
voidshowToast(final Context context, final String string)
show Toast
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
    @Override
    public void run() {
        Toast.makeText(context, string, Toast.LENGTH_LONG).show();
});
voidshowToast(final Context context, final int resId)
show Toast
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
    @Override
    public void run() {
        Toast.makeText(context, resId, Toast.LENGTH_LONG).show();
});
voidshowToast(final Context ctx, final Handler handler, final String text, final int duration)
Schedule a toast message to be shown via supplied handler.
handler.post(new Runnable() {
    public void run() {
        Toast.makeText(ctx, text, duration).show();
});
voidshowToast(final Context ctx, final Handler handler, final int id, final int duration)
Schedule a toast message to be shown via supplied handler.
handler.post(new Runnable() {
    public void run() {
        Toast.makeText(ctx, id, duration).show();
});
voidshowToast(final String toast, final Context context)
show Toast
if (!isAppOnForeground(context))
    return;
new Thread(new Runnable() {
    @Override
    public void run() {
        Looper.prepare();
        Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
        Looper.loop();
...
voidshowToast(final String toast, final Context context)
show Toast
new Thread(new Runnable() {
    @Override
    public void run() {
        Looper.prepare();
        Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
        Looper.loop();
}).start();
...
voidshowToastInThread(final Context context, final String msg)
show Toast In Thread
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
    public void run() {
        showToast(context, msg);
});