Android Webview on 4.4 freezes with nativeOnDraw f

2019-05-23 23:52发布

问题:

I know this question has been asked many times and there are few work arounds.But none of them work for me

I have a app that uses webview . On opening many apps and then waking up this app sometimes makes the webview blank. Other components of the app works but the webview is stuck.

I disabled the hardware acceleration in Androidmanifest.xml and it did not work

<application
    android:name="com.nandish.app.MyApplication"
    android:largeHeap="true"
    android:hardwareAccelerated="false">

I tried to add the following line in to the constructor of Webview

    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Even this does not work. I am able to reproduce the blank screen consistently. When it freezes, the error message on logs are

09-11 23:29:31.237: W/AwContents(2976): nativeOnDraw failed; clearing to background color.

回答1:

The problem with my code was the webView object that was used was getting edited in other place since it was a static variable. My Bad, that was complete disaster to use this object as static. Once I converted to instance variable, it worked.



回答2:

I had the same issue with my WebView and found a pretty simple solution. In my case it was only the way I was giving it the url to load.

Check if your url includes the "http://" in the beginning.

I was trying to load the url from a string with only "www.google.com" and had the "AwContents nativeOnDraw failed; clearing to background color" message on LogCat and a frustrating white screen instead of my site view, this only on KitKat, testing my app on GingerBread was fine. Just by changing it to "http://www.google.com" everything went well.

No hardware acceleration disabled and complete backwards compatibility.



回答3:

I met the same warning message

01-14 21:08:15.854 9400-9400/com.xiaomi.adecom W/AwContents: nativeOnDraw failed; clearing to background color.

When the webview trying to load an invalid url, such as empty url string, or the url string is not started with "http://", the warning occurs.