我正在开发webview应用程序,OnJsAlert中的问题是,当我单击对话框时,它会在关闭<后打开/strong> 它并再次单击它停止我的应用程序,抱歉,我无法通过调试解决问题。
这是我的MainActivity.class
@Override
public boolean onJsAlert(WebView view, String url, final String alertSource, final JsResult alertResult) {
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.activity_alert);
alertDialog.setCancelable(true);
TextView alertMessage = alertDialog.findViewById(R.id.alert_text);
alertMessage.setText(alertSource);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
alertResult.cancel();
}
});
alertDialog.show();
return true;
}
已编辑:日志
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. E/ViewRootImpl: sendUserActionEvent() mView == null W/System.err: android.util.AndroidRuntimeException: requestFeature() must be called before adding content W/System.err: at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:331) at android.app.Dialog.requestWindowFeature(Dialog.java:1057) at com.xcoder.stepview.MainActivity$4.onJsAlert(MainActivity.java:285) at com.android.webview.chromium.WebViewContentsClientAdapter.handleJsAlert(WebViewContentsClientAdapter.java:606) at com.android.org.chromium.android_webview.AwContentsClientBridge.handleJsAlert(AwContentsClientBridge.java:73) at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5641) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104) at dalvik.system.NativeStart.main(Native Method) A/libc: Fatal signal 6 (SIGABRT) at 0x00002c6d (code=-6), thread 11373 (xcoder.stepview) Application terminated.
最佳答案
您的 alertDialog
是在调用 public boolean onJsAlert(...)
方法之前创建的,当您第二次调用该方法时,您会遇到 AndroidRuntimeException: requestFeature() 必须是在添加内容之前调用
,因为您无法在创建的对话框中使用requestWindowFeature()
。您必须在此方法中创建新的对话框实例或重用全局定义的对话框。
关于java - 关闭并再次单击后如何修复对话框中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54455396/