2

I've run into a problem, everything was fine prior SDK 23. But now I get these errors:

W/art: Throwing OutOfMemoryError "Failed to allocate a 61819212 byte allocation with 4032304 free bytes and 3MB until OOM"     
W/JavaBrowserViewRendererHelper: Error allocating bitmap    
E/chromium: [ERROR:java_browser_view_renderer_helper.cc(133)] Error unlocking java bitmap pixels.

And WebView is not displaying. This is my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/post_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff">

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:fillViewport="false"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:scrollbars="vertical"
    android:touchscreenBlocksFocus="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:touchscreenBlocksFocus="false">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/placeholder" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|top"
            android:layout_marginBottom="30dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="30dp"
            android:gravity="center|center_horizontal"
            android:text="Title"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <WebView
            android:id="@+id/webView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/textView"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:scrollbars="none" />

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center" />

        <ImageView
            android:id="@+id/nextprev"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="30dp"
            android:adjustViewBounds="true"
            android:src="@drawable/nextprev" />
    </LinearLayout>
</ScrollView>

As you can see WebView is in ScrollView, cause I want that views above and below WebView to scroll. I've also tried solutions without ScrollView from here Webview in Scrollview and WebView loads just fine, but whatever is above scrolls out but leaves blank space covering WebView.

I don't know, maybe is it just emulator fault? Anyway I would love to know what's causing this and how to solve it.

Community
  • 1
  • 1
bradlol
  • 41
  • 1
  • 6
  • switch to loadDataWithBaseURL, which doesn't require URLEncoder encoding the url, and doesn't keep huge data urls in the history. This seems to have fixed the high cpu use and memory leak, and the SECURITY_ERR: WebView.loadDataWithBaseURL(url,data,"text/html","UTF-8",url); – Jithin Sunny Nov 30 '15 at 12:21
  • I'm already using that. – bradlol Nov 30 '15 at 13:18

1 Answers1

2

I think you had solved this problem, but to answer your question, your emulator was run out of memory (OOM).

I had the same problem managing images, so I think you could reduce the number of images in your app. Additionally, If you want to manage them correctly, I recommend that you see this video https://www.youtube.com/watch?v=JTlJT2b5dd4

If I'm wrong, please correct me.

Jaco
  • 923
  • 2
  • 14
  • 28
  • Yes, it was emulator issue, it worked fine on device. Your video doesn't apply to WebView, so it's not a solution in this case. Anyway I solved it by moving WebView out of ScrollView. – bradlol Mar 20 '16 at 12:39