0

I created a Bitmap and use it in Canvas to draw a circle and this method is called every time the Activity gets called and Activity get called multi-times so that time I am getting some error like 1536000-byte external allocation too large for this process I know that error is Memory issue but how to Clear bitmap and also use at second time Activity call..

My Code is :

private void Draw_Hold_Circle() {
        Bitmap bitmap_hold = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
         Canvas canvas_hold = new Canvas(bitmap_hold);
        canvas_hold.drawArc(rect_open, 0, 360, false, mOutlinePaint);

    }

This Method is called 4 times and the MainActivity can call multi-time so How to maintain Bitmap and its Memory?

fuxia
  • 62,923
  • 6
  • 54
  • 62
ckpatel
  • 1,926
  • 4
  • 18
  • 34

1 Answers1

0

Is there any special reason why you want to mantain the image in memory? If I'm not wrong you call your method "everytime your activity is called" so I'm guessing you mean everytime it's started with startActivity(). If this is the case then there is no point on maintaning all the images in memory at once since the user will be able to see the one on your foreground activity. I would suggest you to save your image to a file on your onStop() method and rebuild it, if necessary, on your onResume() method.

Oscar Rene
  • 361
  • 2
  • 6