I know there is plenty of questions already resolved with the same name as mine, but none of them gave me an answer. Here is what I do :
I have a big multidimensionnal array containing items, each with name, image path, and other stuff. I have a ListView listing all these items from that array, using their names, and when we click on one of these, it opens a new Activity showing the details of the item, and the image. It actually works, the image is well scaled, all loaded things match with the user's click, this part is 100% ok.
But after several clicks, I got OutOfMemory exception. In my previous version of the app, there was no images, and I could click on all the items in a row (almost a hundred items), without any trouble. Now there is images, and out of memory exception. So I assume that images are the problem. Here is how I do to dynamically select an image after a click :
ItemArray items = new ItemArray(itemID); //clicked item ID to match with the array
setContentView(R.layout.activity_show_item);
ImageView itemImage = (ImageView) findViewById(R.id.itemImageView);
Resources res = getResources();
int resID = res.getIdentifier(items.ArrayToPrint[1], "drawable", getPackageName()); //ArrayToPrint = the selected lines matching the item, verification is made in the ItemArray class and is working properly
itemImage.setImageResource(resID);
With this code, the image appears as I want it to. But as I said earlier, I got OutOfMemory exception. I tried several things to flush caches, but none worked, I still got this problem, and don't know how to deal with it.
Any clues ? Thanks in advance !