0

In the "drawable" folder I have four background images of 1024 x 768 or something.

However, it turns out to be that I have to use Bitmap.createScaledBitmap() and my Android device is 2560 x 1504. Which means a Bitmap with the size of 2560 x 1504 is required to fill the whole screen with a background, it is really memory-consuming because it is a Bitmap of impressive size.

For some reason, I need to cache 4 bitmaps like this so my program can instantly switch to a new background when I press a button. Which means I am facing huge memory problems now. Is there any way to optimize it?

P.S: I am using ImageView class to display images. The images files in the "drawable" folder are not BMP files.

  • 1
    save those images in external memory not in cache memory – saurabh dixit Aug 21 '17 at 05:28
  • Good idea. I want to know how to do that. –  Aug 21 '17 at 05:34
  • i think glide might be useful read this article https://medium.com/@multidots/glide-vs-picasso-930eed42b81d – Manohar Aug 21 '17 at 05:34
  • I do not think I need external libraries right now. I am learning the basics. –  Aug 21 '17 at 05:37
  • I solved my question for now, by loading each image the moment you need them. Loading all images at once on startup will cause a very high memory consumption and may result in a memory exception. –  Aug 21 '17 at 06:14
  • You can use Glide , instead of writing your own code which may cause many issues and bugs , You can use well established and efficient library like glide , Its very easy to use .. – Omar Dhanish Aug 21 '17 at 06:15
  • Thank you, I will look at it and see. –  Aug 21 '17 at 06:26

0 Answers0