Skip to content Skip to sidebar Skip to footer

Outofmemoryerror In My Gridadapter

I'm trying create adapter for my gridView which should contains photo, which I chose in gallery. But I have following OutOfMemoryError in line 'return row' public class GridViewAd

Solution 1:

Image loading is a way way more complex thema than this, if you're interested on it, there's lots of topics/blog/etc you can read online. But StackOverflow is a direct question-answer, so,

To fix the issue, import this library: https://github.com/square/picasso

and then replace those lines:

Filef=newFile(images_urls.get(position));  
UriimageUri= Uri.fromFile(f);
holder.image.setImageURI(imageUri);

with:

Picasso
  .with(holder.image.getContext())
  .load(image_urls.get(position))
  .into(holder.image);

this library will take care of proper managing the memory. Make sure to further check the library API as you can put extra commands to resize the image on-screen so it uses less memory.

Solution 2:

In Your AndroidManifest.xml

add android:largeHeap="true" to your < application >

<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.example.sample"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="18" /><applicationandroid:largeHeap="true"android:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="com.example.sample.MainActivity"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application>

And to avoid OutofMemory Error you should use Universal Image Loader Link or Picasso Library Link.

Post a Comment for "Outofmemoryerror In My Gridadapter"