Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.widget.Toast;

public class Main {
    /**
     * A method to create a toast message on any screen.
     *
     * @param activity : screen on which the toast message should be shown.
     * @param msg      : the message to be shown.
     */
    public static void createToastMessage(final Activity activity, final String msg) {
        if (!isNullOrEmpty(msg))
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast toast = Toast.makeText(activity.getApplicationContext(), msg, Toast.LENGTH_SHORT);
                    toast.show();

                }
            });
    }

    /**
     * A method to check whether a string is null or empty.
     *
     * @param String .
     * @return boolean true or false.
     */
    public static boolean isNullOrEmpty(String s) {
        return s == null ? true : (s.trim().length() <= 0);
    }
}