Singleton to show a toast - Android User Interface

Android examples for User Interface:Toast

Description

Singleton to show a toast

Demo Code


//package com.java2s;
import android.content.Context;
import android.widget.Toast;

public class Main {
    private static Toast toast;

    /**//  ww  w . j  ava2  s  .c o m
     * Singleton to show a toast
     * @param context Application context
     * @param message Toast message
     */
    public static void makeSingleShowToast(Context context, int message) {
        if (toast != null) {
            toast.cancel();
        }
        toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
        toast.show();
    }
}

Related Tutorials