アニメーションを開始する前に初期化し、終了したらすぐにリサイクルする AnimationDrawable があります。問題は、アニメーションを再度開始するときに、すべてを再初期化しても例外が発生することです。
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@2bbad018
これが私のコードです
public ImageView radarImageView;
public AnimationDrawable animationDrawable;
public void animationStart() {
// animationStop();
radarImageView = (ImageView) findViewById(R.id.radarIV);
radarImageView.setBackgroundResource(R.drawable.sensor_animation);
animationDrawable = (AnimationDrawable) radarImageView.getBackground();
animationDrawable.start();
}
public void animationStop() {
animationDrawable.stop();
for (int i = 0; i < animationDrawable.getNumberOfFrames(); ++i){
Drawable frame = animationDrawable.getFrame(i);
if (frame instanceof BitmapDrawable) {
((BitmapDrawable)frame).getBitmap().recycle();
}
frame.setCallback(null);
}
animationDrawable.setCallback(null);
// animationDrawable = null;
// radarImageView.setBackgroundResource(0);
}
全体を再度初期化しないのはなぜですか?