I am using ViewFlipper in my android app. After calling startflipping() if I let app to run for some minutes I get soon the error :
11-22 15:36:34.354: ERROR/dalvikvm-heap(428): 307200-byte external allocation too large for this process.
11-22 15:36:34.372: ERROR/(428): VM won't let us allocate 307200 bytes
11-22 15:36:34.375: ERROR/AndroidRuntime(428): Uncaught handler: thread main exiting due to uncaught exception
11-22 15:36:34.384: ERROR/AndroidRuntime(428): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:296)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at com.PlayerOrange.ViewPlaylist.populate(ViewPlaylist.java:115)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at com.PlayerOrange.ViewPlaylist.access$0(ViewPlaylist.java:100)
11-22 15:36:34.384: ERROR/AndroidRuntime(428): at com.PlayerOrange.ViewPlaylist$ProgressTask$1$1.run(ViewPlaylist.java:383)
Every 30 seconds I get some info about memory like this :
ActivityManager activityManager = (ActivityManager) getBaseContext().getSystemService(ACTIVITY_SERVICE);
android.app.ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
Log.i(TAG, " memoryInfo.availMem " + memoryInfo.availMem + "\n" );
Log.i(TAG, " memoryInfo.lowMemory " + memoryInfo.lowMemory + "\n" );
Log.i(TAG, " memoryInfo.threshold " + memoryInfo.threshold + "\n" );
What's strange is that before I get Force Close (for outofmemoryError) I have in DDMS this :
11-22 15:36:10.255: INFO/(428): memoryInfo.availMem 50470912
11-22 15:36:10.255: INFO/(428): memoryInfo.lowMemory false
11-22 15:36:10.264: INFO/(428): memoryInfo.threshold 16777216
I have no idea how to solve this error.
Here is my code for populating ViewFlipper
:
private void populate() {
for (int i = 0; i < jArray.length(); i++) {
System.out.println("lungime" + jArray.length());
LinearLayout l = new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
l.setBackgroundColor(0x000000);
l.setOrientation(LinearLayout.VERTICAL);
vf.addView(l);
File f = new File(Environment.getExternalStorageDirectory()
+ "/Downloads/");
File[] files = f.listFiles();
Bitmap bitmap = BitmapFactory.decodeFile(files[i].getPath());
img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
img.setImageBitmap(bitmap);
System.out.println("target " + target[i]);
img.setOnTouchListener(this);
img.setId(i);
l.addView(img);
img = null;
}
vf = (ViewFlipper) findViewById(R.id.details);
vf.setFlipInterval(Integer.valueOf(timer) * 1000);
vf.startFlipping();
populate();
I get the images from web and save to Sdcard. After that I get them from folder of SDcard and add them to viewFlipper.
Any idea is welcome. Thanks in advance.