0

My webView started to lag so bad, when I scroll it down, it suddenly goes back to the top of the site displayed in it, and some days ago it worked perfectly. with a movement of my thumb it used to go all down to the bottom of the site with no issues.

I´ve been trying to fix this issue, I suppose it started after I had to make the following changes in the manifest:

android:hardwareAccelerated="false"
android:largeHeap="true"

I did this change because suddenly my app started to crash when starting, and looking on the web I found that setting the hardwareAcellerated to false could be a possible solution, and it worked the app started to work normally but the webView was affected bad.

this is the error I got from logcat when changing the hardwareAccelerated="true":

08-27 04:46:01.722 20554-20554/com.newapp.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.newapp.test, PID: 20554
java.lang.RuntimeException: Canvas: trying to draw too large(139560960bytes) bitmap.
    at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
    at android.graphics.Canvas.drawBitmap(Canvas.java:1420)
    at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
    at android.widget.ImageView.onDraw(ImageView.java:1286)
    at android.view.View.draw(View.java:18398)
    at android.view.View.updateDisplayListIfDirty(View.java:17376)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1964)
    at android.view.View.updateDisplayListIfDirty(View.java:17371)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.view.View.updateDisplayListIfDirty(View.java:17371)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.view.View.updateDisplayListIfDirty(View.java:17371)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.view.View.updateDisplayListIfDirty(View.java:17371)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.view.View.updateDisplayListIfDirty(View.java:17371)
    at android.view.View.draw(View.java:18160)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
    at android.view.View.draw(View.java:18401)
    at com.android.internal.policy.DecorView.draw(DecorView.java:969)
    at android.view.View.updateDisplayListIfDirty(View.java:17376)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:722)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:728)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:836)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:3168)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2964)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2552)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
    at android.view.Choreographer.doCallbacks(Choreographer.java:734)
    at android.view.Choreographer.doFrame(Choreographer.java:670)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6776)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

If you can tell me where I can find that bitmap the error says, it would be very appreciated because in my drawable folder i have none. The bigger image file is a 90kb png.

I tried to keep the hardwareAccelerated="false" in manifest, and use this solution I found in here:

        if (Build.VERSION.SDK_INT >= 15) {
        // 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);
    }

but it didn´t work either.

Btw I´m using this to force the site to load inside the webView:

   inner class MyClient : WebViewClient() {
    override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
        view.loadUrl(url)
        return true
    }
}

These are my webview settings:

        webView.apply {
        settings.javaScriptEnabled = true
        settings.setSupportZoom(true)
        settings.setBuiltInZoomControls(true)
        settings.setDisplayZoomControls(false)
        settings.loadWithOverviewMode = true
        settings.useWideViewPort = true
        webViewClient = MyClient()

    }

and this is my webView:

        <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />
</LinearLayout>

thank you in advance for your support.

  • so some websites are heavy its not like they will load in a blink, i would say use progress bar to show the loading of website, and let it load completely. – Abdul Kawee Aug 27 '18 at 10:14
  • the wesites are completely loaded, is the scrolling stuff that is lagging like hell, it goes back to the top of the page with no reason, and it happens in every website. This didnt happen before. ty anyway for your comments Abdul – Gabo Walker Aug 27 '18 at 10:22
  • Usually `Canvas: Trying to draw too large` is due to bitmaps in your application. If you have any of image (jpg/png) then you can try moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi and then true to make the hardware acceleration true. Have you tried `getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)` Refer to [this link](https://stackoverflow.com/a/32304329/8085421) If your website is loading fully at first then its very likely that the problem lies in the hardware acceleration. – Usama K. Zafar Aug 27 '18 at 11:57
  • it worked!!! moving the heaviest image (a .png of 91kb) to drawable-xxhdpi. Thank you very much!!1 – Gabo Walker Aug 27 '18 at 13:49

0 Answers0