I am using a webview in my application. Webview is created using application context . App crashes on clicking any select box
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 been asked already many times, but I am yet to find any working solution. This problem will get solved if I use activity context but I have to use application context due to some other concerns. For other alerts and dialogs I have handled them by overriding onJsAlert() in webchromeclient, but I am not able to find how I can intercept this in my webview and create my own selector dialog.
Any kind of suggestions/help is much appreciated.
Adding a dummy sample of my webview implementation
class MyWebView extends WebView
{
MyWebView(Context context)
{
super(context.getApplicationContext());
setWebChromeClient(myWebChromeClient);
setWebViewClient(myWebViewClient);
}
}