android onResume不恢复图像值

时间:2013-03-21 20:00:16

标签: android bitmap recycle

我使用AnimationDrawable动画,动画完成或活动关闭即可回收位图。所以我第一次开始活动并且动画正在发生,但是如果我关闭活动并再次打开它,我会收到错误trying to use a recycled bitmap

为什么onResume代码没有重新创建图像值?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    animationImage = (ImageView) animation_dialog.findViewById(R.id.ivAnimation);
    animationImage.setBackgroundResource(R.drawable.animation);
    animationImage.post(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            animation = (AnimationDrawable) animationImage.getBackground();
            animation.start();
        }
    });
}

@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    animation.stop();
    animation_dialog.dismiss();

    for (int i = 0; i < animation.getNumberOfFrames(); ++i) {

        Drawable frame = animation.getFrame(i);
        if (frame instanceof BitmapDrawable) {
            ((BitmapDrawable) frame).getBitmap().recycle();
        }
        frame.setCallback(null);
    }
    animation.setCallback(null);
}

@Override
protected void onResume() {
    super.onResume();
    animationImage.setBackgroundResource(R.drawable.animation);
    animation = (AnimationDrawable) animationImage.getBackground();
}

0 个答案:

没有答案