5

Is it possible to load a url from a WebView without having it attached to any layout (not visible)?

1
  • 1
    Yes. Just don't add it to your view. Create the WebView dynamically. Commented Aug 21, 2015 at 22:42

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
Try to instantiate any other View with an ApplicationContext, most have unexpected side effects.
If I do it like this, I get the error: "validate_display:99 error 3008 (EGL_BAD_DISPLAY)"
This solution works... (or at least worked) try loading a simple web page with just a label and see..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.