0

I am having an issue of this. I want to add those pictures as they have some kind of index but i have tried to add to array and now hashmap. Now the same error occurs.

How am I suppose to add those images to indexes that it doesn't use all memories? I am trying to make quiz game and I have indexed the right answer as number 0-21.

Error picture

chazefate
  • 822
  • 4
  • 13
  • 35
  • Try compressing those images. If transparency is not critical then make them jpegs – Peter Chaula Dec 09 '16 at 22:36
  • Cant you just use smaller images? Do have to load all images to memory at the same time? Maybe you can load them latef in tve program and then unload tvem – user3532232 Dec 09 '16 at 22:41

1 Answers1

1

The error occurs because all your drawables are decoded as bitmaps. Consider to store the int id in your Collection (like R.drawable.someimagename) and get the real Drawable object just in time when it's needed.

Since you have constant number of entries with indices from 0-21, you can use an array:

int[] groundForceDrawables = new int[22];
groundForceDrawables[0] = R.drawable.sotamies_kauluslaatta;
groundForceDrawables[1] = R.drawable.korpraali_kauluslaatta;
// and so on

When you really need to draw the image at index i:

Drawable myCurrentDrawable = getResources().getDrawable(groundForceDrawables[i]);

This will only be suitable if you do not have to display all the drawables at the same time. If you have to keep the Drawable objects in cache together since you have to display them all at the same time, I still recommend to scale them down, your heap will be large enough to save Bitmaps to fill the screen unless their resolution is needlessly high.

Also you can increase your heap size if you haven't done that already: How to increase heap size of an android application?

Community
  • 1
  • 1
C. L.
  • 571
  • 1
  • 8
  • 26