Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;

import android.content.Context;

import android.text.TextUtils;
import android.widget.Toast;

public class Main {
    private static Toast mToast;

    public static void ToastMsg(Context context, String msg) {
        if (context == null || TextUtils.isEmpty(msg)) {
            return;
        }
        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
        mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        mToast.show();
    }

    public static void ToastMsg(Context context, int resourceId) {
        if (context == null) {
            return;
        }
        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
        mToast = Toast.makeText(context, resourceId, Toast.LENGTH_SHORT);
        mToast.show();
    }

    public static void ToastMsg(final Activity activity, final String msg) {
        if (activity == null || TextUtils.isEmpty(msg)) {
            return;
        }
        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (mToast != null) {
                    mToast.cancel();
                    mToast = null;
                }
                mToast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
                mToast.show();
            }
        });
    }
}