New WebView in Android KitKat problems

3.1k Views Asked by At

My app is using a WebView to display a long text

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView mWebView = new WebView(getApplicationContext());

    setContentView(mWebView);

    String s = getHtml(); //get a long html from a file

    webView.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "UTF-8", null);
}

the app works well on older versions of Android,
but when running on KitKat, this error appears in the logcat when the WebView is created or destroyed:

libGLESv2(21582): HWUI Protection: wrong calling from app context F:ES3-glDeleteShader

I have read "Migrating to WebView in Android 4.4" but I cannot solve the problem.

How do I fix this?

2

There are 2 best solutions below

2
On

Change

WebView mWebView = new WebView(getApplicationContext());

to

WebView mWebView = new WebView(this);
0
On

add

webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);