Android Webview Hardware Acceleration Artefact Workarounds

Android WebView Hardware Rendering Weird Artifact Issue

Thanks to Delyan for solving the issue. How he told me to solve it was to add -webkit-transform: translate3d(0,0,0) to all parts that move.

KUDOS DELYAN!

Hardware Acceleration stops working on new APIs

Tested on API 18:

Perform the check by posting a Runnable to the WebView:

WebView webView = (WebView) findViewById(R.id.webview_id);

// Shows: "Is hardware accelerated? false"
// Toast.makeText(YourActivity.this, "Is hardware accelerated? " +
// webView.isHardwareAccelerated(),
// Toast.LENGTH_LONG).show();

webView.post(new Runnable() {

@Override
public void run() {
Shows: "Is hardware accelerated? true"
Toast.makeText(YourActivity.this, "Is hardware accelerated? " +
webView.isHardwareAccelerated(),
Toast.LENGTH_LONG).show();

if (webView.isHardwareAccelerated()) {
// isAccelerated();
} else {
// isNotAccelerated();
}
}
});

From resource page on Hardware Acceleration:

Hardware acceleration is enabled by default if your Target API level
is >=14, but can also be explicitly enabled.

If the image you are displaying is still pixelated, try setting:

webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

and see if pixelation of the image gets better.

Consider reading the resource page on Hardware Acceleration.

Android webview slow

It depends on the web application being loaded. Try some of the approaches below:

Set higher render priority (deprecated from API 18+):

webview.getSettings().setRenderPriority(RenderPriority.HIGH);

Enable/disable hardware acceleration:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// chromium, enable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

Disable the cache (if you have problems with your content):

webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

Slow page transitions on Android with hardware acceleration on

It seems like Ionic has made a lot of Android-related fixes that really improved performance. In addition, I've splitted my Android version into two versions: 4.4 and pre-4.4. Pre 4.4 is using cordova-android-chromeview which makes it so much faster. Even though it adds ~20 MB to the apk, it worths it.



Related Topics



Leave a reply



Submit