Is it possible to load a url from a WebView without having it attached to any layout (not visible)?
1 Answer
Yes, you can use your application context to instantiate your WebView:
WebView webView = new WebView(getApplicationContext()); webView.loadUrl("your-url"); Surprisingly this works... which means that a webview can actually be created with the application context and does not need a UI context which for me is a bit weird.
4 Comments
Mikhail Naganov
It is absolutely normal. You can render off-screen and then display the result as you want. E.g. a ebook reader can render the pages of the book off-screen, and then when displaying, apply a visual effect for page turning, which would be quite hard to implement in CSS.
TacB0sS
Try to instantiate any other View with an ApplicationContext, most have unexpected side effects.
SeikoTheWiz
If I do it like this, I get the error: "validate_display:99 error 3008 (EGL_BAD_DISPLAY)"
TacB0sS
This solution works... (or at least worked) try loading a simple web page with just a label and see..
WebViewdynamically.