import android.widget.Toast;
/**
* Created by chao0 on 2016/5/26.
*/
public class ToastUtils {
private static Toast toast;
//双重判断确保整个程序只有一个吐司
public static void toastShow(String text){
if (toast==null){
synchronized (ToastUtils.class){
if (toast==null){
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
}
}else{
toast.cancel();
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
toast.show();
}
//运行在工作线程的吐司
public static void showWorkThread(final String text){
ThreadPoolUtils.runTaskOnUIThread(new Runnable() {
@Override
public void run() {
toastShow(text);
}
});
}
//运行在ui线程的吐司
public static void showUIThread(String text){
toastShow(text);
}
}
/**
* Created by chao0 on 2016/5/26.
*/
public class ToastUtils {
private static Toast toast;
//双重判断确保整个程序只有一个吐司
public static void toastShow(String text){
if (toast==null){
synchronized (ToastUtils.class){
if (toast==null){
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
}
}else{
toast.cancel();
toast=Toast.makeText(AppUtils.getBaseContext(),text,Toast.LENGTH_SHORT);
}
toast.show();
}
//运行在工作线程的吐司
public static void showWorkThread(final String text){
ThreadPoolUtils.runTaskOnUIThread(new Runnable() {
@Override
public void run() {
toastShow(text);
}
});
}
//运行在ui线程的吐司
public static void showUIThread(String text){
toastShow(text);
}
}