2

頻繁に呼び出すことができるアクティビティがあります。アクティビティは、画像を表示して 3 秒後に終了するスプラッシュ スクリーンの形式です。ただし、2 回目に頻繁に呼び出されると、アクティビティがクラッシュします。

以下はコード スニペットです。

public class SplashActivity extends Activity {
    private long splashDelay = 3000; //3 seconds

    ImageView imageView = null;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = getIntent().getExtras();
        int value = b.getInt("key");


        imageView = new ImageView(this);
        imageView.setImageResource(Utility.getImageIDofGalleryAlphabets(value));
        setContentView(imageView);


        TimerTask task = new TimerTask()
        {

            @Override
            public void run() {
                 BitmapDrawable bitmapDrawable  = ((BitmapDrawable) imageView.getDrawable());

                    if (null != bitmapDrawable && !bitmapDrawable.getBitmap().isRecycled()) {

                        bitmapDrawable.getBitmap().recycle();
                    } 
                    bitmapDrawable = null;
                imageView = null;
                finish();

            }

        };

        Timer timer = new Timer();
        timer.schedule(task, splashDelay);
    }
}

以下は実行時例外です。

    java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@448dec68
at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323)
at android.widget.ImageView.onDraw(ImageView.java:923)
at android.view.View.draw(View.java:6739)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
at android.view.ViewRoot.draw(ViewRoot.java:1422)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

よろしくお願いします

4

0 に答える 0