在Android的OutOfMemory错误 [英] OutofMemory error in Android

查看:128
本文介绍了在Android的OutOfMemory错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了一个游戏,它使用的图像和我的比赛是在纵向和横向模式。 我有2个不同的布局为 当我从1方向切换到其他,做这5 6次后,它给强制关闭的错误 错误是这样的:

I have created one game which uses images and my game is in portrait and landscape mode. I have 2 different layout for that When i switch from 1 orientation to other, after doing this 5 6 times, it gives force close error Error is like :

产生的原因:java.lang.OutOfMemoryError:位图大小超过VM预算

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

任何人都知道解决的办法?有没有什么办法来清理切换方向的所有影像? 在此先感谢

Anyone know the solution? is there any way to clean up all images in switching orientation ? thanks in advance

推荐答案

我得到了这个环节的解决方案 http://android-developers.blogspot.com/2009/01 /avoiding-memory-leaks.html

i got the solution from this link http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

我有很多图片在ImageView的每次方向更改设置。 我只是做backgorund图像静态的,问题就解决了​​。

i have a lots of images are setting in imageview every time orientation changes. i just make backgorund image static and problem solved

private static Drawable BackgroundP;
private static Drawable BackgroundL;

if (conf.orientation == Configuration.ORIENTATION_LANDSCAPE){
   if(BackgroundL == null){
      BackgroundL = getResources().getDrawable(R.drawable.backgroundland);
   }
} else {
   if(BackgroundP == null){
      BackgroundP = getResources().getDrawable(R.drawable.backgroundport);
   }
}

这将只设置drawble一次。

this will only set drawble one time.

希望这将帮助任何人。

这篇关于在Android的OutOfMemory错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆