アプリの多くのアクティビティでanimationdrawablesを使用しています。これは、それらを初期化するためのコードです。
public void prepareVideo (int resourceBall, String animation, int width, int height ){
imgBall = (ImageView)findViewById(resourceBall);
imgBall.setVisibility(ImageView.VISIBLE);
String resourceNameAnimation = animation;
int id_res = getResources().getIdentifier(resourceNameAnimation, "drawable", getPackageName());
imgBall.setBackgroundResource(id_res);
LayoutParams latoutFrame = imgBall.getLayoutParams();
latoutFrame.width = width;
latoutFrame.height = height;
imgBall.setLayoutParams(latoutFrame);
frame = (AnimationDrawable) imgBall.getBackground();
}
次に、次のように呼び出します。imgBall.post(new StartAnimation());
ランナブルと呼ばれるもの:
class StartAnimation implements Runnable {
public void run() {
frame.start();
}
}
問題は、同じxml(フレームごと)を使用する多くのアニメーションを使用することです。同じアニメーションの多くのアクティビティでこのメソッドを呼び出す必要があります。最後に、メモリ不足エラーが発生します。画面間でメモリを解放しようとしています:
for (int i = 0; i < frame.getNumberOfFrames(); ++i){
Drawable frame_rescue = frame.getFrame(i);
if (frame_rescue instanceof BitmapDrawable) {
((BitmapDrawable)frame_rescue).getBitmap().recycle();
}
frame_rescue.setCallback(null);
問題は、リソースをもう一度使用しようとすると、「リサイクルされたビットマップを使用しようとしています」という他のエラーが発生することです。
誰もがメモリを解放する他の方法を知っていますか?