Universal Image Loader与三星设备的内存不足

时间:2014-07-10 14:12:10

标签: android caching universal-image-loader inflate-exception

我和我的应用程序一起使用Universal Image Loader和许多设备(联想,HTC,LG等),但三星的一切都崩溃了。在我的应用程序中,我使用ListView获得了几个fragents。那些ListView只包含图像,我从网上下载并希望通过UIL显示。

但是当我在三星(S4 / Galaxy Tab 3 / Galaxy Note 8.0)上调试我的应用程序时,LogCat给了我这个:

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)

和应用程序崩溃。

只有三星设备才会出现这种情况!我从来没有在另一个品牌上使用过这种Exeption。 这就是我在我的适配器中使用UIL的方式:

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;
}

和我的布局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>

这就是我配置Universal Image Loader的方法:

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

我一直在尝试毕加索,但我也遇到了同样的问题,所以我有可能因为记忆力差,但等等,为什么?我一直在尝试使用DiscCache并遇到这个问题,所以可能它们都没有相互连接。你能救我吗?

更新

我从布局中删除了模式图像,现在我没有InflateException但是奇怪的OutOfMemoryError。但是,如果我仅将我的图像缓存在光盘上怎么可能呢?

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)

1 个答案:

答案 0 :(得分:1)

  

但是当我在三星(S4 / Galaxy Tab 3 / Galaxy Note 8.0)上调试我的应用程序时,LogCat会给我Out of memory on a 30355216-byte allocation

您正在尝试分配~30MB的堆空间作为扩充布局的一部分。这不太可行。我不知道它与UIL有什么关系,因为UIL没有参与通货膨胀过程。

相反,这可能来自@drawable/pattern,因为它与布局的第16行绑定,并且是唯一可能消耗大量内存的东西。