最近在做一个项目突然发现以前的按2次关闭应用的提示应用都退出了还一直显示,这样严重影响效果必须解决掉。
public static Toast toast = null;
public static int LENGTH_LONG = Toast.LENGTH_LONG;
private static int LENGTH_SHORT = Toast.LENGTH_SHORT;
private static Context context = null;
/**
* 普通文本消息提示
*
* @param context
* @param text
*/
public static void TextToast(Context context, CharSequence text) {
if (toast != null) {
// toast.cancel();
toast.setText(text);
// 设置Toast提示消息在屏幕上的位置
toast.setDuration(LENGTH_SHORT);
} else {
ToastUtil.context = context;
toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
// 设置Toast提示消息在屏幕上的位置
toast.setGravity(Gravity.CENTER, 0, 0);
}
// 显示消息
toast.show();
}
@Override protected void onPause() {
System.out.println("onPause() ");
toast.cancel(); super.onPause();
}