1

I have a 3MB image with resolution 1920*1080, when I try to load this image on a Real Device (441 PPI & 5.5 inch screen : Oneplus2 Device) it works fine. But when I run this code on a emulator device (1GB Ram | 441 PPI density|5.5 inch screen) then i am getting the OutOfMemoryError . I am Loading the image to the Background of my RelativeLAyout via XML.

I checked the Devloper.android for loading the bitmaps efficiently but it was not much clear to me. So can you please help me out.

Kainix
  • 1,186
  • 3
  • 21
  • 33
  • set largeHeap in to application tag in AndroidManifest and read this: http://developer.android.com/intl/vi/training/displaying-bitmaps/load-bitmap.html – Brian Hoang Apr 24 '16 at 05:54
  • The bitmap needs the image data in uncompressed form and will therefore be at least 8MB big. The 3MB on the file system are irrelevant. – Henry Apr 24 '16 at 08:08
  • if i will allocate the Large Heap then it will not be the clever idea since apps will consume large memory and it will make slow performance on there device and subsequently crash – rahul shrivastava Apr 24 '16 at 09:13

1 Answers1

1

It happen on device to device I had similar problem. Everything was working fine on my Sony Xperia C(1GB RAM)but it was giving OOM in Xiomi Redmi(2GB RAM).

Then I done all sort of painful research on how to load Bitmap efficiently and end up using Glide Library and since then I never saw any OOM in my project.

Integration is simple simply add Jar in your project and load bitmap of any size simply :-

 ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  Glide.with(this).load("url to 3 MB image").into(imageView);

You can read all about glide here https://futurestud.io/blog/glide-getting-started

Community
  • 1
  • 1
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154