Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save SelvinPL/916ea634693fda05545b to your computer and use it in GitHub Desktop.

Select an option

Save SelvinPL/916ea634693fda05545b to your computer and use it in GitHub Desktop.
//naive way of not getting OOME (still terrible but...)
//in loop DO NOT DECODE TO BITMAP
//map.put(TAG_Photo, bitmap); should become:
map.put(TAG_Photo, Base64.decode(photo, Base64.DEFAULT)); //byte array take less space than coresponded base64 string
SimpleAdapter adapter = ...;
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if(view.getId() == R.id.imageView1) { //view is our ImageView
ImageView imageView = (ImageView)view;
Drawable drawable = imageView.getDrawable();
//trying to recycle old bitmap to avoid OOME
if (drawable != null && drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmapold = bitmapDrawable.getBitmap();
bitmapold.recycle();
}
byte[] imageAsBytes = (byte[])data;
//TERRIBLE IDEA - IT SHOULD BE DONE ON NON UI THREAD
Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
imageView.setImageBitmap(bitmap);
return true;
}
//Otherwise do default stuff
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment