Issue
I'm developing webview app, the problem in OnJsAlert that when i click on the Dialog it opens after dismiss it and click again it stop my app, for sorry i can't get the problem from debugging.
This is my 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;
}
Edited : Log
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.
Solution
Your alertDialog is created before public boolean onJsAlert(...) method called and when it's called second time you got AndroidRuntimeException: requestFeature() must be called before adding content because of you can't use requestWindowFeature() with created dialog. You have to create new instance of dialog in this method or reuse global defined dialog.
Answered By - Stanislav Bondar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.