has already been added to the window manager

 把判断去掉

if (toast == null) {
                toast = new Toast(MyApplication.getInstance());
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.setDuration(Toast.LENGTH_SHORT);
                View _root =                       LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.toast_custom_common, null);
                mTvToast = (TextView) _root.findViewById(R.id.tvCustomToast);
                toast.setView(_root);
            }
            try{
                mTvToast.setText(content);
                toast.show();
            }catch (Exception e){}

改成

try{
                toast = new Toast(MyApplication.getInstance());
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.setDuration(Toast.LENGTH_SHORT);
                View _root = LayoutInflater.from(MyApplication.getInstance()).inflate(R.layout.toast_custom_common, null);
                mTvToast = (TextView) _root.findViewById(R.id.tvCustomToast);
                toast.setView(_root);
                mTvToast.setText(content);
                toast.show();
            }catch (Exception e){}

后来发现问题出在自定义的Toast。重新进入时,之前的那个view没有销毁;但是又重新被添加。所以才会报错

你可能感兴趣的:(android)