I have no clue what to about this exception, since I try to discard each bitmap as they've been used and flush the stream to where I write these images. I use this method to save bitmaps to a PDF, but the idea is probably the same as just exporting a number of Bitmaps in a row.
I use itextpdf (http://mvnrepository.com/artifact/com.itextpdf/itextpdf)
// List of pages containing draw objects that can be converted to bitmaps
ArrayList<Page> pages;
Rectangle pageSize = new Rectangle(width, height);
Document document = new Document(pageSize, 0, 0, 0, 0);
PdfWriter.getInstance(document, new FileOutputStream(saveDirectory));
document.open();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
for (int i=0; i < pages; i++)
{
// From a list of objects, draws them on a Bitmap canvas and returns the bitmap.
Bitmap b = DrawEngine.Draw(width, height, originalWidth, originalHeight, pages.get(i).GetDrawObjects());
stream.flush();
stream.reset();
b.compress(CompressFormat.PNG, 100, stream);
b.recycle();
byte[] byteImage = stream.toByteArray();
Image image = Image.getInstance(byteImage);
document.add(image);
// Update notification
System.gc();
}
document.close();