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

  • Home
  • SEARCH
  • 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 6863729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:49:20+00:00 2026-05-27T02:49:20+00:00

I have two simple activities A and B . The user starts B from

  • 0

I have two simple activities A and B. The user starts B from A by pressing a button, and the user then returns to A by pressing the back button.

In the onDestroy() method of activity B I recycle some background images used in activity B. What I am trying to understand is why, when activity B is started again, I am getting ‘trying to use a recycled bitmap’. Surely the bitmaps will be loaded again in the onCreate() method? like they must have been on the first time the activity was launched.

Here is my example code:

public class ActivityB extends Activity {

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);    
         setContentView(R.layout.selectionpage);    
     }  

     @Override
     public void onDestroy() {      
        ImageView iv = (ImageView) findViewById(R.id.imageView1);
        ((BitmapDrawable)iv.getDrawable()).getBitmap().recycle();
        LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout1);
        ((BitmapDrawable)ll.getBackground()).getBitmap().recycle();
        super.onDestroy();
     }
 }

The code I use to launch activity B from A

     Intent intent = new Intent(ActivityA.this, ActivityB.class);
     startActivity(intent);

selectionpage.XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/backgroundimage">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/selectionimage"/>
        </LinearLayout>                

This part may be relevant. I’m not sure. I’ve noticed that after launching activity B, even after it has been destroyed, I can still see an instance of my activity when analyzing the memory heap using MAT. The path to GC roots seems to go through Java.lang.Thread and ContextImpl.

  • 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-05-27T02:49:21+00:00Added an answer on May 27, 2026 at 2:49 am

    You get that error because ImageView iv & LinearLayout ll are still pointing to recycled bitmaps. You don’t need to do recycling yourself inside onDestroy(). Bitmaps will be freed when they are not needed by the system.

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

Sidebar

Related Questions

I have an application which consists of two activities/screens and a java class from
I have two activities: one displays an image and a button, the other displays
I have two activities, Activity A and Activity B. Activity B is creating a
I have two activities, A and B. Activity A implements a LocationListener that periodically
I have two simple custom controls derived from standard WPF controls. I.e. internal class
I have two simple tables in my database. A card table that contains Id,
I have two simple while loops in my program that I feel ought to
Let's say I have two simple models project t.string :title vote t.references :project t.integer
I have two very simple, identical UITableViews in my app that are populated with
I have two geo-spatial simple convex polygon areas, in latitudes and longitudes (decimal degrees)

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.