I am working on an android application. I have an activity that contains a list view.
The list view has lots of items and each contains a bitmap image.
Because the list is very big and contains a lot of images it is giving and out of memory error on some old devices when loading the bitmaps.
So I am looking for a way to do the following for old devices:
Is there a way to do it?
Additional information:
I have followed every instructions and code on how to load Bitmap images efficiently (on the android documentation and on any site that I could find), I also made sure there is no memory leaks, I recycle every bitmap and make sure the GC works correctly and finally, on old devices I made the resolution of the images the smallest possible. But the size of the list is causing the out of memory to still appear on some devices.
So I am looking to know if I can do the above proposed solution.
Thanks a lot for any help
You should consider looking at Sample Gallery App from Google I/O 2012. Everything you need is implemented there.
Video from Google I/O about gallery app
Source code is available on Google Code and it's an exclellent example of building a Gallery. You should also consider looking at Romain Guy's presentation (beginning) where he explains performance issues with ListView
and teaches to use adapters efficiently. (ViewHolder pattern and reusing views).
Here's a RecycleListener for GridView (Available from API level 1). A RecyclerListener is used to receive a notification whenever a View is placed inside the RecycleBin's scrap heap. This listener is used to free resources associated to Views placed in the RecycleBin.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.album);
mAdapter = new PhotoAdapter(this);
mGridView = (GridView) findViewById(android.R.id.list);
mGridView.setAdapter(mAdapter);
mGridView.setRecyclerListener(new RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
// Release strong reference when a view is recycled
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
imageView.setImageBitmap(null);
}
});
// Kick off loader for Cursor with list of photos
getLoaderManager().initLoader(LOADER_CURSOR, null, mCursorCallbacks);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With