everybody!
I draw a plot based on some data in my app. The plot is with scrolling and zooming. I create 2 bitmaps for this purpose in MyMainFragment.onActivityCreated().
if (bitmaps[0] != null)
{
return;
}
final int deviceWidth = getResources().getDisplayMetrics().widthPixels;
final int deviceHeight = getResources().getDisplayMetrics().heightPixels;
final int deviceMaxDim = Math.max(deviceHeight, deviceWidth);
bitmaps[0] = Bitmap.createBitmap(
deviceMaxDim * 2,
deviceMaxDim * 1,
Bitmap.Config.ARGB_8888);
bitmaps[1] = Bitmap.createBitmap(
bitmaps[0].getWidth(),
bitmaps[0].getHeight(),
bitmaps[0].getConfig());
I need 2 bitmaps and not only 1 because of the drawing algorithm I use. Running the program on Asus Transformer, the bmp size in pixels is 1280 * 2 * 1280, thus the byte size being 1280 * 2 * 1280 * 4. When I run the program from Eclipse, everything’s fine. But when I launch it like an ordinary user from the tablet, it crashes every second time.
What’s happening behind the scene when I launch my app from Eclipse that allows it to run and can I follow the same steps programmatically so that it doesn’t crash when launched normally? Or should I use some other drawing algorithms (maybe something like OpenGL)?
Thanks a lot.
The solution was simple. I created a Canvas somewhere in my code, called Canvas#setBitmap(bitmaps[?]) on it, but didn’t realise, that I must call Canvas.setBitmap(null) to free the reference.