Android Question Out of Memory when using Canvas

RichyK68

Active Member
Licensed User
Longtime User
Hi,

What's the correct way of dealing with a Canvas? I've got an activity that creates a canvas from a panel, initializes two bitmaps, which are drawn onto the canvas. I get an Out of Memory when opening/closing the activity a certain number of times. I've tried the recyle trick that I found in the forums, but I then get a 'cannot draw recycled bitmaps' error on closing the activity. I'm guessing the recycle trick is similar to the Dispose method in .Net but it's just giving me grief.

Cheers,

Richard

ps I have orientation sensor code calling a paint method on this activity if it's not paused, to update the canvas. I thought perhaps this was causing the 'cannot draw recycled ...' error, but even with setting a flag to True before I recycle, and checking this flag and exiting the paint method if the flag is set, I still got the error.
 

RichyK68

Active Member
Licensed User
Longtime User
When I do the following

Dim r As RSImageProcessing

r.recycle(thecanvas.Bitmap)

If I recycle the bitmaps (in _Pause that are created in _Resume) that are drawn onto the canvas I have no problems but if I recycle the bitmap on the canvas, as above, I get java.lang.IllegalArgumentException: Cannot draw recycled bitmaps. It's obviously coming from my method that paints to the canvas, not the recycle call itself, but I've tried wrapping my paint code in try...catch to no avail, and I've tried setting a flag to true just before recycling and in the paint method checking this flag, but my app still just fails miserably with no way of controlling it.

Any ideas?

Cheers,

Richard

ps if I shouldn't use the orientation sensor to handle orientation changes, what is the alternative?
 
Upvote 0
Top