-1

i'm developing an app with in one activity a lot imageview. Sometimes when i try to start it this crash with an "outOfMemory" error.Here it is my activity code:

   ImageView [] immagini = new ImageView[11];
String [] vett;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_techp);
    Intent intent = getIntent();

//obtaining array from previous activity

    vett=intent.getExtras().getStringArray("nomeImmagine");
//Instance ImageView
    for (int i = 0; i < 11; i++){
        int x=i+1;
        immagini[i] = (ImageView) findViewById(getResources().getIdentifier("imageView"+x, "id", getPackageName()));
    }
//setting image resource
    for (int i = 0; i < vett.length; i++) immagini[i].setImageResource(getResources().getIdentifier(vett[i],"drawable", getPackageName()));
}

Any idea how can i resolve this?

Cristian Bregant
  • 1,797
  • 1
  • 16
  • 22
  • possible duplicate of [Strange out of memory issue while loading an image to a Bitmap object](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – Simon Jan 25 '14 at 17:46

1 Answers1

0

You will need to cache your images, go here and see what Googles says about it. Always keep in mind that Android devices have a limited amount of memory, and may vary greatly according to each device.