1

In my application are a lot of images resources. Use for animation and also for embedded gallery. My question is - where to store that resources ? I must bind that data with application - no downloading during installation. Currently all my images are stored in drawable folder. But , for example, when i try to get images for gallery (grid view) i get Out off memory exception. This happens also when i try to run animation.

I should store that images in sdcard, and load it when I need it. And then free resources from memory. How to do it - put resources in assets / raw ,then save in sd card ? Then load it ?

Please help me with this.

Bandzio
  • 617
  • 2
  • 10
  • 21

2 Answers2

0

There are many SO questions related to this:

Save bitmap to location

How do I transfer an image from its URL to the SD card?

However, this won't solve your OutOfMemoryProblem. That's most likely cause, in this case, when the images are too large. You can shrink them before you install the application. Another way is to resize them programmatically.

Community
  • 1
  • 1
DeeV
  • 35,865
  • 9
  • 108
  • 95
  • Not sure whether resizing them programatically is going to be too useful - you still have to load the big image before you shrink it. – Elemental Oct 26 '11 at 12:41
  • One at a time though. It's better than all large images all at once. – DeeV Oct 26 '11 at 12:45
  • How about pack my resources in zip folder, put it in assets folder. When app is first run - zip content is save in sdcard andimages are read from sdcard - i will save some memory right ? I don't have to store all images in drawable, i just load what i need when i need and after that - free resources. What do you think about it ? – Bandzio Oct 26 '11 at 13:00
0

It seems to me for what you want the method of including the images in drawables is convenient and practical.

However if the images are so large that you can't load them into memory simultaneously then you have a different problem.

The first thing I would do is check that the out of memory IS caused by the size of the images - try making the images much smaller and see if you get a similar error then you know that your app is probably doing something horrible (memory leak on load or display?).

If the image size is the problem BUT the app is starting up correctly then you need to make a plan to only load the images from the resources as you need to display them (as opposed to loading all the images before you display any) and to dispose of these resources when the image is no longer required.

Depending on your situation and context there are several well understood methods for this kind of lazy loading as required with some buffering.

Elemental
  • 7,365
  • 2
  • 28
  • 33