我正在开发一个应用程序,在一个活动中有很多imageview。有时当我尝试启动它时会出现“outOfMemory”错误。这是我的活动代码:
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()));
}
我知道如何解决这个问题?
答案 0 :(得分:0)
您需要缓存图片go here and see what Googles says about it。请记住,Android设备的内存有限,根据每台设备的不同,可能会有很大差异。