Android的setBackgroundResource释放内存? [英] Android setBackgroundResource release memory?

查看:882
本文介绍了Android的setBackgroundResource释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个安静的大动画每个50pics一个20KB 这两个定义为动画的.xml

I have 2 quiet big Animations each 50pics a 20kb Both defined as Animations .xml

一个让我从一开始就和后一个按钮,点击第二个开始。

One I let start from the beginning and the second after a button click.

//Start immediatly
  imgView.setBackgroundResource(R.layout.anim1);
                rocketAnimation = (AnimationDrawable) imgView.getBackground();

//Start after button click
  imgView.setBackgroundResource(R.layout.anim2);
                rocketAnimation = (AnimationDrawable) imgView.getBackground();

它工作正常,直到我按下按钮并指定第二阿尼姆我的看法

It works fine, till i hit the button and assign the second anim to my view

08-22 14:56:03.886: DEBUG/AndroidRuntime(1541): Shutting down VM
08-22 14:56:03.886: WARN/dalvikvm(1541): threadid=3: thread exiting with uncaught exception (group=0x4001da28)
08-22 14:56:03.886: ERROR/AndroidRuntime(1541): Uncaught handler: thread main exiting due to uncaught exception
08-22 14:56:04.096: ERROR/AndroidRuntime(1541): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 14:56:04.096: ERROR/AndroidRuntime(1541):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

看起来definitly每个动画本身是好的(我甚至可以设置anim2在自动启动)。但双方会超过内存。

It looks definitly that each animation for itself is fine (i could even set anim2 at the autostart). but BOTH will exceed the memory.

顺便说一句。在我的Nexus One就可以完美运行。当它失败是G1 1.6(即使在模拟器)。

Btw. on my Nexus One it works perfect. Where it fails is on G1 1.6 (even in Simulator).

因此​​,如何将我释放anim1之前,首先我给anim2 ??

So HOW would I release anim1 first before I assign anim2 ??

THX 克里斯

推荐答案

试着运行

rocketAnimation.setCallback(null);

您展示anim2之前。

before you show anim2.

BTW:N1具有每允许(24MB)比G1(16MB)的应用程序更多的堆。三星Galaxy S更是把(48MB)。但是通过参数,你还可以设置一个较高的堆限制仿真器; (不幸的是没有一个无根的手机虽然)。

btw: N1 has more heap per app allowed (24mb) than the G1 (16mb). Samsung Galaxy S has even more (48MB). But via parameter you can also set a higher heap limit for the emulator; (unfortunately not for an unrooted phone though).

这篇关于Android的setBackgroundResource释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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