Sep 16, 2010
My app, among other things, downloads and displays images from the Internet. Some might be too large and trigge an OOM when ImageView.setImage() is called. Of course, this normally makes the application to crash. I've put catch (OutOfMemoryError e) around the method invocation. I know that catching errors is unusual, but in JSE applications it proved to work pretty good, especially when the problem was due to image manipulation that consumed all the memory. The Android app seemed to survive for a while, but then it blocked the computer. All buttons are irresponsive, even though the phone seems still alive (e.g. it's playing the audio notification that new email has been spotted). I tried holding the power button, it triggered the shut down menu, but touching a menu option didn't do anything. Only after a while, the phone became responsive again.
View 2 Replies
Now, it's reasonable that one can't display everything on a smartphone; I'm sure there's some inefficient memory management I'm doing (perhaps keeping too many images in memory); ok, I have to improve my code. Given that I'll do, how can I add some safety facility to avoid the most severe consequences? Making an irresponsive application it's a 100% sure way to make people to uninstall my app and give bad reviews. I'm thinking of a two-pronged safety approach: 1) whether it's possible to understand in advance whether an image is too large to be rendered by itself;
2) whether it's possible to recover from an OOM in any case.