bitmap size exceeds VM budget
10-19 16:20:44.617: ERROR/AndroidRuntime(13274):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
at android.content.res.Resources.loadDrawable(Resources.java:1713)
at android.content.res.Resources.getDrawable(Resources.java:585)
at cn.sinonet.uhome.ui.bulbcurtain.util.BmpUtil.getBmpByResid(BmpUtil.java:12)
at cn.sinonet.uhome.ui.bulbcurtain.util.BmpUtil.getBmpByWidth(BmpUtil.java:19)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.loadSwitchBgBmp(UnscaledLight.java:247)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.loadBmp(UnscaledLight.java:221)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.onDraw(UnscaledLight.java:205)
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
at android.content.res.Resources.loadDrawable(Resources.java:1713)
at android.content.res.Resources.getDrawable(Resources.java:585)
at cn.sinonet.uhome.ui.bulbcurtain.util.BmpUtil.getBmpByResid(BmpUtil.java:12)
at cn.sinonet.uhome.ui.bulbcurtain.util.BmpUtil.getBmpByWidth(BmpUtil.java:19)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.loadSwitchBgBmp(UnscaledLight.java:247)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.loadBmp(UnscaledLight.java:221)
at cn.sinonet.uhome.ui.bulbcurtain.view.UnscaledLight.onDraw(UnscaledLight.java:205)
点击返回键时回收图片内存资源
void recycleBmp(Bitmap bmp)
{
if(bmp != null && !bmp.isRecycled())
bmp.recycle();
}
void recycleBmp()
{
recycleBmp(bmpBg);
recycleBmp(bmpSwitchBg);
recycleBmp(bmpSwitchOn);
recycleBmp(bmpSwitchOff);
recycleBmp(bmpSwitch);
recycleBmp(bmpBulbOn);
recycleBmp(bmpBulbOff);
recycleBmp(bmpBulb);
}
UnscaledLight
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
Log.i("smart_home", "++UnscaledLight.onKeyDown++");
recycleBmp();
}
return super.onKeyDown(keyCode, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
Log.i("smart_home", "++UnscaledLight.onKeyDown++");
recycleBmp();
}
return super.onKeyDown(keyCode, event);
}
SmartUHomeActivity
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
Log.i("smart_home", "++SmartHomeActivity.onKeyDown++");
}
Log.i("smart_home", "super.onKeyDown::" + super.onKeyDown(keyCode, event));
// return super.onKeyDown(keyCode, event);
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
Log.i("smart_home", "++SmartHomeActivity.onKeyDown++");
}
Log.i("smart_home", "super.onKeyDown::" + super.onKeyDown(keyCode, event));
// return super.onKeyDown(keyCode, event);
return false;
}
LOG日志
10-19 17:00:56.762: INFO/smart_home(16185): ++SmartHomeActivity.onKeyDown++
10-19 17:00:56.772: INFO/smart_home(16185): super.onKeyDown::true
10-19 17:00:56.772: INFO/smart_home(16185): super.onKeyDown::true