public class ToastUtil {
private static WeakReference<Toast> sToast;
public static void show(CharSequence content) {
if (TextUtils.isEmpty(content)) {
return;
}
if (sToast != null && sToast.get() != null) {
sToast.get().setText(content);
sToast.get().show();
} else {
Toast toast = Toast.makeText(MyApplication.getApp(), content, Toast.LENGTH_SHORT);
sToast = new WeakReference<>(toast);
toast.show();
}
}
public static void cancel() {
if (sToast != null && sToast.get() != null) {
sToast.get().cancel();
}
}
}
网友评论