[英]Out of memory exception for static images used in application
Let's say i have 10 activities, and each contain a static image, I am finishing and starting a new activity on left and right click of the arrow. 假设我有10个活动,每个活动都包含一个静态图片,我正在按箭头的左键和右键单击完成并开始一个新的活动。
Images are in drawable folder and are a bit large size, As far as i think, if a activity finishes then all the memory it's using is freed(that's why i had taken so many activities), but it's not happening. 图像位于可绘制的文件夹中,并且有点大,据我认为,如果一个活动完成,那么它正在使用的所有内存都将被释放(这就是为什么我进行了如此多的活动),但是这没有发生。
If constantly go on clicking the right and left button, the app freezes and crashes(out of memory exception). 如果持续单击左右按钮,则该应用程序将冻结并崩溃(内存不足异常)。
Is there any way to avoid this? 有什么办法可以避免这种情况?
1- Load your images using: 1-使用以下方法加载图像:
BitmapFactory.decodeResource(res, id, opts);
Use inSampleSize in Options
to rescale your image. 使用“
Options
inSampleSize重新缩放图像。
2- Recycle your bitmap in onDestroy()
. 2-在
onDestroy()
回收位图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.