0

I've been working with Universal Image Loader and many devices (Lenovo, HTC, LG etc.) with my app but with Samsung everything crashes. In my app I've got several fragents with ListView. Those ListViews contains only images, which I download from web and want to display by UIL.

But when I debug my app on Samsung (S4/Galaxy Tab 3/Galaxy Note 8.0) LogCat gives me this:

07-10 14:49:33.685: E/dalvikvm-heap(29613): Out of memory on a 30355216-byte allocation.
07-10 14:49:33.705: E/AndroidRuntime(29613): FATAL EXCEPTION: main
07-10 14:49:33.705: E/AndroidRuntime(29613): Process: com.ready4s.bookapart, PID: 29613
07-10 14:49:33.705: E/AndroidRuntime(29613): android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
07-10 14:49:33.705: E/AndroidRuntime(29613):    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
07-10 14:49:33.705: E/AndroidRuntime(29613):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
.
.
.
07-10 14:49:33.705: E/AndroidRuntime(29613):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
07-10 14:49:33.705: E/AndroidRuntime(29613):    at com.ready4s.bookapart.adapters.FavouriteAdapter.getView(FavouriteAdapter.java:101)

and app crashes.

It only happens with Samsung devices! I never had this kind of Exeption on another brand. This is how I use UIL in my adapter:

private LayoutInflater mInflater;

protected ImageLoader mImageLoader = ImageLoader.getInstance();
public FavouriteAdapter(Activity activity) {

    mImageOptions = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.pattern)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();
    mActivity = activity;
    mInflater = activity.getLayoutInflater();
}

///////blah blah blah

class ViewHolder {

    public ImageView mApartmentImage;

}

///////blah blah blah

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    FavouriteApart apartment = mFavouriteApartsList.get(position);
    ViewHolder vHolder;
    View view = convertView;

    if (view == null) {
        view = mInflater.inflate(R.layout.apartment_favourite_last_seen_object_row, null);
        vHolder = new ViewHolder();
        vHolder.mApartmentImage = (ImageView)view.findViewById(R.id.apartament_image_view);
        view.setTag(vHolder);
    } else
        vHolder = (ViewHolder)view.getTag();

    mImageLoader.displayImage(apartment.getURL(), vHolder.mApartmentImage, mImageOptions);

    return view;
}

and my layout apartment_favourite_last_seen_object_row:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/search_fragment_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/search_default_margin"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <ImageView
            android:id="@+id/apartament_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/pattern" />
    </RelativeLayout>
</RelativeLayout>

This is how I configure my Universal Image Loader:

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            getApplicationContext()).threadPoolSize(4).memoryCache(new LruMemoryCache(2*1024*1024))
            .build();
    ImageLoader.getInstance().init(config);

I've been trying Picasso and I had the same problem, so I't possible that I'm pretty much out of memory but, wait, why? I have been trying with DiscCache only and had this problem so maybe it's all not connected with each other. Can you help me?

UPDATE

I removed pattern images from layout and now I don't have InflateException but strange OutOfMemoryError. But how is it possible if I for example cache my images only on disc?

08-21 10:38:16.440: E/dalvikvm-heap(19619): Out of memory on a 4194320-byte allocation.
08-21 10:38:16.861: E/dalvikvm-heap(19619): Out of memory on a 4194320-byte allocation.
08-21 10:38:16.901: E/AndroidRuntime(19619): FATAL EXCEPTION: GLThread 31270
08-21 10:38:16.901: E/AndroidRuntime(19619): Process: com.ready4s.bookapart, PID: 19619
08-21 10:38:16.901: E/AndroidRuntime(19619): java.lang.OutOfMemoryError
08-21 10:38:16.901: E/AndroidRuntime(19619):     at android.graphics.Bitmap.nativeCreate(Native Method)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at android.graphics.Bitmap.createBitmap(Bitmap.java:903)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at android.graphics.Bitmap.createBitmap(Bitmap.java:880)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at android.graphics.Bitmap.createBitmap(Bitmap.java:847)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at opl.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at opp.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at opp.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at opp.b(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at oow.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at ope.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at okm.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at ojx.a(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at ojx.b(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at otq.k(Unknown Source)
08-21 10:38:16.901: E/AndroidRuntime(19619):     at otq.run(Unknown Source)
Roval
  • 508
  • 1
  • 4
  • 21

1 Answers1

1

But when I debug my app on Samsung (S4/Galaxy Tab 3/Galaxy Note 8.0) LogCat gives me Out of memory on a 30355216-byte allocation

You are trying to allocate ~30MB of heap space as part of inflating a layout. This is unlikely to work. I am not aware that it would have anything directly to do with UIL, as UIL is not involved in the inflation process.

Instead, this probably coming from @drawable/pattern, seeing as it is tied to line #16 of the layout and is the only thing in there that could consume significant memory.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That's something. Now I don't have InflateException but OutOfMemoryError. But still, how is it possible if I cache my images? I will update my question. – Roval Aug 21 '14 at 09:02
  • My bad. I've changed some options and now it's working! The pattern was a couse of the problem. Great! – Roval Aug 21 '14 at 10:08
  • @Roval can I know wheat changes you have changed?? – Ashton Mar 06 '17 at 09:37
  • @Devon As far as I remember I just removed thumbnail image reference from XML file. The problem was that Samsung device was loading thumbnail image to the memory every time it was displaying the cell. – Roval Mar 07 '17 at 17:31