show Message using Toast via WeakReference - Android User Interface

Android examples for User Interface:Toast

Description

show Message using Toast via WeakReference

Demo Code


//package com.java2s;
import android.content.Context;
import android.widget.Toast;
import java.lang.ref.WeakReference;

public class Main {
    public static void showMessage(Context context, String message) {
        WeakReference<Context> contextWeakReference = new WeakReference<Context>(
                context);/* w  w  w.j  a  v a2s.c om*/
        Toast.makeText(contextWeakReference.get(), message,
                Toast.LENGTH_SHORT).show();
    }
}

Related Tutorials