Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:02:44+00:00 2026-06-08T19:02:44+00:00

I send message to this handler(here I ommitted some cases) to do some operation

  • 0

I send message to this handler(here I ommitted some cases) to do some operation on a bitmap and then set the bitmap on the UI. Because the operation on the bitmap is time consuming, I put it in a thread. When I finishing doing this, I set the UI in the UI thread with the method runOnUiThread.
Normally, all this runs well, but in some cases I got the following exception: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap.
It occurs very rare, but it did happened several times.

private Handler mHandler = new Handler()
{
    @Override
    public void handleMessage(Message msg)
    {
        int what = msg.what;
        switch (what)
        {

            case VideoProtocal.COMPRESS_SUCCESS:
                state = State.COMPRESSED;
                recordBack.setVisibility(View.VISIBLE);
                recordSend.setVisibility(View.VISIBLE);
                playButton.setVisibility(View.VISIBLE);
                new Thread(){
                    @Override
                    public void run()
                    {
                        rotationBitmap();
                        runOnUiThread(new Runnable() {
                            public void run() {
                                if( null != bitmap && !bitmap.isRecycled() )
                                {
                                    Drawable drawable = new BitmapDrawable(bitmap);
                                    fristFrame.setBackgroundDrawable(drawable);
                                }
                            }
                        });
                    }
                }.start();
                mFrameCount = 0;
                getVideoSize();
                videoTime = getVideoFileTime(mp4_path) / 1000;
                timeView.setText(getString(R.string.video_count, videoTime));
                deleteTempFile();
                LogX.trace(TAG, "COMPRESS_SUCCESS");
                dismissProgress();
                break;
            default:
                break;
        }
    }

};

The method rotationBitmap() and some method it calls is shown as bellow:

private void rotationBitmap()
{
    int width = (int) (PIC_WIDTH * FusionField.currentDensity);
    int height = (int) (PIC_HIGHT * FusionField.currentDensity);
    Bitmap bmTemp = bitmap;
    bitmap = CommonUtil.resizeImage(bitmap, width, height);

    if (bmTemp != null && !bmTemp.isRecycled() && bmTemp != bitmap)
    {
        bmTemp.recycle();
        bmTemp = null;
    }

    rotate(bitmap, rotationAngle());

    CommonUtil.checkMysoftStage(FusionCode.videoThumbnail);
    String videoName = CommonUtil.getUniqueName(".jpg", FusionCode.videoName);
    jpg_path = FusionCode.videoThumbnail + "/" + videoName;
    try
    {
        FileOutputStream fos = new FileOutputStream(jpg_path);
        if (bitmap != null)
        {
            bitmap.compress(CompressFormat.JPEG, 50, fos);
        }
        fos.close();
    }
    catch (FileNotFoundException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


private Bitmap rotate(Bitmap b, int degrees)
{
    if (degrees != 0 && b != null)
    {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try
        {
            bitmap = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
        }
        catch (OutOfMemoryError ex)
        {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        }
    }
    return b;
}

From the code, the problem must ocuured in this statement:

Drawable drawable = new BitmapDrawable(bitmap);

but according to the code context, the bitmap should’t be null or recycled, that’really strange.

I have been hanging around this issue nearly two days and can’t figure it out what the problem is, but the issue does exists. Could anybody give me some suggestions? Any response is appreciated! Thanks!

By the way, when I try to the RuntimeException like this, this kind of exception can’t be catched, WHY?

try
{
    bitmap.recycle();
    Drawable drawable = new BitmapDrawable(bitmap);
    fristFrame.setBackgroundDrawable(drawable);
}
catch (RuntimeException e)
{
    e.printStackTrace();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:02:46+00:00Added an answer on June 8, 2026 at 7:02 pm

    Okey, let me answer my question. The problem occurs because the VideoProtocal.COMPRESS_SUCCESS was received by mHandler twice. It has multi-thread there, so at some point, the “used a recycled bitmap” problem occurs.
    As to why twice message was received, er… that’s my fault use of timer task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a hub which should send message to specific user and this Question
I am trying to send a message, using MailCore framework in iOS. This is
I am trying to send a soap message to an external system, this system
This is my code to send mail (test code): //sending mail var message =
This may seem like a stupid question, but what message do i send to
I want to use a menu to send a message to handler. And handler
Hi I want to send message from one application (which will be installed on
when I send message as client using quickfix, how can I know if it's
I want to send message/notification to friends with customized subject with a link in
I am trying to use PostMessage to send a tab key. Here is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.