Android layer type with webview white screen-first time loading webview very slow

Source: Internet
Author: User

Encountered in the project WebView when loading the picture will appear white screen, and then set the WebView attribute in XML, the problem to solve:

@SuppressWarnings ("Deprecation") @Overrideprotected voidOnDestroy () {if(Mwebview! =NULL){           Try { //Mwebview.clearview (); //Mwebview.loadurl ("About:blank"); Mwebview.clearcache (true); Mwebview.destroy ();//form Destruction, to webview destruction; Consider security issues and memory overflow}Catch(Exception e) {e.printstacktrace (); }} mylog.e (TGA,"Form Destruction"); Isdestroy=true;          System.GC (); Super. OnDestroy (); }  

< WebView    Android:id = "@+id/webview"              android:layout_width= "Fill_parent"              android:layout_height= "Fill_ Parent "            android:layertype=" Software "             android:scrollbars= "None"/>  

There are also some information on the layer on the Internet:

The following excerpt from http://blog.csdn.net/a345017062/article/details/7478667

Let's talk about these three layers.

Layer_type_software whether or not hardware acceleration is turned on, there will be a bitmap (software layer) and soft rendering of webview on top. Benefits: When animating, use software to draw a view tree only once, which is very provincial. When not to use: Do not use the view tree when it is updated frequently. Especially when hardware acceleration is turned on, each update consumes more time. Because after rendering this bitmap, it is necessary to render this bitmap to the hardware layer.

Layer_type_hardware hardware acceleration off, the function is the same as software. Hardware acceleration is rendered on FBO (Framebuffer Object) when it is turned on, and the view tree only needs to be drawn once when animating.

The difference between the two: 1, one is rendered to bitmap, one is rendered to FB. 2, hardware may have some operations not supported. The same: both open a buffer and draw the view to this buffer.

Layer_type_none This is relatively simple, do not create a separate layer for this view tree

The Ps:glsurfaceview and webview default Layertype are none.

Glsurfaceview: To Glsurfaceview set to software or hardware, found what also can not draw out. Concludes that the Glsurfaceview layer type can only be none

WebView: The previous use of WebView encountered a problem, if the WebView above the use of Animation,webview painting area does not move. The solution at the time was to take a screenshot of the WebView before animating it (Drawingcache). According to the above reason to try, set a hardware or software layer is OK.

Now another problem, after turning on hardware acceleration, on some machines (mine is 3.2) WebView Sometimes there is an area white screen problem. The default layer type is none, and hardware is not possible, and setting it to software is resolved. Of course, hardware acceleration is turned off, but then the overall program is slower. So the final solution is the overall hardware acceleration, the problem of the WebView setup software

Added on 2012.4.21:

Add this sentence to make the 3D draw faster: Getholder (). SetType (Surfaceholder.surface_type_hardware);

Added on 2012.4.22

First of all: when hardware acceleration is turned on, Glsurfaceview is removed from the view tree, causing the entire window background to darken, even if the layer type is set to software. After two days of troubleshooting, found the reason, my program is in the C layer by drawframe (belonging to the glthread thread) to drive the painting, when Glsurfaceview was taken off, Glsurfaceview destroy method is called, I called the end method of the Glthread thread directly in the Destroy method (which belongs to the UI thread). While Glsurfaceview.creat,sizechanged,destroyed is on the UI thread, Render.create,sizechanged,drawframe is on the glthread thread. Therefore, there is a problem with the way that the UI thread calls the Glthread thread directly.  Finally, the problem is resolved by sending runnable through glsurfaceview.queueevent to the glthread thread.  It seems that the soft rendering of the fault-tolerant ability, a hardware acceleration, the bottom is more fragile. Conclusion: Be sure to figure out which is the UI thread and which is the glthread thread.

Make up a few points of knowledge found in the process of finding a problem: hardware acclerator is the acceleration of the entire window, View.ishardwareacclerator returns True when hardware acceleration is turned on. However, each view may be rendered to a different Canvas, such as the view may be set by Setlayer layer, then canvas.ishardwareaccelerator return False Android provides three types of hardware acceleration whether the control level is turned on, respectively, Application,activity,window,view. This can be referred to the dev Guide

Android layer type with webview white screen-first time loading webview very slow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.