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