I wrote this in onBindViewHolder of RecycleViewAdapter,
Bitmap.createBitmap( 240, 420, Bitmap.Config.RGB_565);
And I got OutofmemoryError when scrolling my RecycleView. Down size of image is not good solution because error will happen when memory not enough.
Please help, thanks.
-
why do you need to createBitmap in onBindViewHolder ?pskink– pskink2015年07月23日 06:49:39 +00:00Commented Jul 23, 2015 at 6:49
-
I have come across this issue couple of time and resolved using following link developer.android.com/training/displaying-bitmaps/…user4571931– user45719312015年07月23日 06:52:31 +00:00Commented Jul 23, 2015 at 6:52
1 Answer 1
Ofcourse it gives you OutOfMemory Exception.
Do you know how many times does your adapter call the onBind method?
A LOT. And you create a bitmap every time. You don't reuse it, you don't recycle it, you create it over and over again.
What do you use that Bitmap for more exactly? Maybe you don't even need to create it every time.
You should use a cache mechanism, you can use a library to display the Bitmap (like Universal Image Loader, Glide, Picasso, Volley, Lazy loading).