Getting Bitmap from WebView generates OutOfMemory crash

爱⌒轻易说出口 提交于 2019-12-04 00:18:51

Okay, I've cracked this one meself. The problem indeed was in the fact that the function returned the Bitmap waay before the zooming out procedure was over, so I had to delay it.

I incorporated

Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //bulk of my code
            }
        }, 1000);

which forced to change the structure of the function from public Bitmap to public void. Here's directly related thread. Despite some minor tweaks I still need to fix, the approach works like a charm

Quick fix:-

Set android:largeHeap="true" in your AndroidManifest.xml file.

<application
    android:name="yourapplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher_rounded"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:roundIcon="@mipmap/ic_launcher_rounded"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

Gud luck :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!