以下代码用于检索所有照片以便在gridview上显示。但是,如果我有1000张照片,则会导致内存不足错误。有没有人可以帮忙解决这个问题?
P.S。如果有人可以,你能够显示上面编辑的代码来使用延迟加载和缓存吗?我很丢失。初始化方法主要用于设置将由gridview
使用的ImageAdapter谢谢!
public void initialize() {
images.clear();
final String[] columns = { MediaStore.Images.Thumbnails._ID };
final String orderBy = MediaStore.Images.Media._ID;
@SuppressWarnings("deprecation")
Cursor imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
null, null, orderBy);
if(imagecursor != null){
int image_column_index = imagecursor
.getColumnIndex(MediaStore.Images.Media._ID);
int count = imagecursor.getCount();
for (int i = 0; i < count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
ImageItem imageItem = new ImageItem();
imageItem.id = id;
lastId = id;
imageItem.img = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
images.add(imageItem);
}
//imagecursor.close();
}
notifyDataSetChanged();
}