0

我使用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();
}
4

0 回答 0