Dialog最好不要判断是否为空, 每次都直接new

本文探讨了Android应用开发中遇到的异常问题,特别是关于`android.view.WindowManager$BadTokenException`的错误信息及其解决方法。通过实例演示,展示了如何避免使用无效令牌导致的窗口无法正常显示的问题,并提供了相关代码修改建议。

异常:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@42fe4230 is not valid; is your activity running?

10-08 18:57:07.696: E/AndroidRuntime(16021): at android.view.ViewRootImpl.setView(ViewRootImpl.java:736)

10-08 18:57:07.696: E/AndroidRuntime(16021): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)

10-08 18:57:07.696: E/AndroidRuntime(16021): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:74)

10-08 18:57:07.696: E/AndroidRuntime(16021): at android.app.Dialog.show(Dialog.java:322)

 

代码:

if(mDialog != null){

   mDialog = new Dialog(mMainActivity, XXXXXX);

}

mDialog.show();

 

去掉判断,每次都重新new就OK了

function createMergeDialog(bomDetailIdList){ //正整数正则表达式 const regex = /^[1-9]\d*$/; //创建新窗口 ReactAPI.createDialog("newDialog", { title: "创建虚拟物料", url: "/msService/RM/formulaBOM/formulaBomMain/formulaBomMergeEdit", buttons: [ { text: "关闭", type: "cancel", onClick: function (event) { ReactAPI.destroyDialog("newDialog"); //parent.location.reload(); } }, { text: "确认", type: "primary", onClick: function (event){ //保存校验,5个校验的顺序为从下至上 //“物料类别”字段仅作为展示,实际与流程无关 if(!regex.test(ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol4").getValue())){ ReactAPI.getIframeWindow("newDialog").ReactAPI.showMessage("w", "\"单锅桶数\"应为正整数!"); return false; } if(ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol4").getValue() == ""){ ReactAPI.getIframeWindow("newDialog").ReactAPI.showMessage("w", "\"单锅桶数\"为!"); return false; } if(ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol3").getValue() == ""){ ReactAPI.getIframeWindow("newDialog").ReactAPI.showMessage("w", "\"物料名称\"为!"); return false; } if(ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol2").getValue() == ""){ ReactAPI.getIframeWindow("newDialog").ReactAPI.showMessage("w", "\"物料编码\"为!"); return false; } if(ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol1").getValue() == ""){ ReactAPI.getIframeWindow("newDialog").ReactAPI.showMessage("w", "\"物料类别\"为!"); return false; } ReactAPI.getIframeWindow("newDialog").ReactAPI.openLoading("处理中"); setTimeout(function(){ //传参给后端新建虚拟物料以及虚拟BOM var res = ReactAPI.request({ type: "post", data: { "code" : ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol2").getValue(), "name" : ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol3").getValue(), "singleVessel" : ReactAPI.getIframeWindow("newDialog").ReactAPI.getComponentAPI().Input.APIs("extraCol4").getValue(), "cid": ReactAPI.getUserInfo().company.id, "factoryId": ReactAPI.getComponentAPI().Reference.APIs("formulaBomMain.factory.code").getValue()[0].id, "bomDetailIdList" : bomDetailIdList }, url: "/msService/RM/formulaBOM/formulaBomMain/createVirtualZjBom", async: false }); if(res.code == 200){ ReactAPI.getIframeWindow("newDialog").ReactAPI.closeLoading(); ReactAPI.showMessage('s', "生成虚拟BOM成功!"); setTimeout(function(){ var url = "/msService/RM/formulaBOM/formulaBomMain/dgBomEdit?viewCode=RM_1.0.0_formulaBOM_dgBomList&entityCode=RM_1.0.0_formulaBOM&iscrosscompany=false&openType=frame&buttonCode=RM_1.0.0_formulaBOM_dgBomList_BUTTON_update&iscallback=true&id=" + res.data; const newWindow = window.open(url, "_blank"); ReactAPI.destroyDialog("newDialog"); // 刷新当前页面 window.location.reload(); },3000); }else{ ReactAPI.getIframeWindow("newDialog").ReactAPI.closeLoading(); ReactAPI.showMessage('w', "生成虚拟BOM错误!"); } },1000) } } ] }); }这段js有什么语法错误
最新发布
07-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值