Faster Loading images in GridViews or ListViews in Android using Menory Caching, Complete implemenation with sample code.
This example shows you how to load large images in the gridview without any lag or without outofmemory error. This sample application uses the LruCache to hold the images. A cache that holds strong references to a limited number of values. Each time a value is accessed, it is moved to the head of a queue. When a value is added to a full cache, the value at the end of that queue is evicted and may become eligible for garbage collection. Read more from here. http://developer.android.com/reference/android/util/LruCache.html This is the MainActivity that holds the GridView. We are adding here 100 images in the Grid to load. This time I am loading images from the resources. MainActivity.java import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.widget.GridView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...