Application error when clicking selection button in webview

I am using webview in my application. Webview is created using the application context. Application error when clicking on any selection field

04-10 14:19:14.502: E/AndroidRuntime(12628): Uncaught handler: thread main exiting due to uncaught exception
04-10 14:19:14.542: E/AndroidRuntime(12628): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.view.ViewRoot.setView(ViewRoot.java:476)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.app.Dialog.show(Dialog.java:239)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.webkit.WebView$InvokeListBox.run(WebView.java:9509)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.os.Handler.handleCallback(Handler.java:609)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.os.Looper.loop(Looper.java:123)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at android.app.ActivityThread.main(ActivityThread.java:4595)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at java.lang.reflect.Method.invokeNative(Native Method)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at java.lang.reflect.Method.invoke(Method.java:521)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-10 14:19:14.542: E/AndroidRuntime(12628):    at dalvik.system.NativeStart.main(Native Method)

I am well aware that this question has already been asked many times, but I have not yet found a working solution. This problem will be resolved if I use the activity context, but I have to use the application context due to some other problems. For other warnings and dialogs, I handled them by overriding onJsAlert () in the webchromeclient, but I cannot find how I can intercept this in my webview and create my own selection dialog.

Any suggestions / help are welcome.

Adding a dummy sample of my webview implementation

class MyWebView extends WebView
{

 MyWebView(Context context)
 {

    super(context.getApplicationContext());
    setWebChromeClient(myWebChromeClient);
    setWebViewClient(myWebViewClient);
 }
}
+5
source
2

, WebView . Android WebView, WebView , , . , Activity, Application. :

super(context.getApplicationContext());

:

super(context);

, - , ( ). - , , .

+3

, extends Activity .

.

webView , .

mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
0

All Articles