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 6724767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:43:43+00:00 2026-05-26T09:43:43+00:00

In my main activity (with launchmode set as singleTask ), I have a TabHost

  • 0

In my main activity (with launchmode set as singleTask), I have a TabHost with three tabs, which all contain a custom Gallery that displays Views containing a bitmap image which is stored locally (once we have server support, these will be downloaded instead).

The problem I am running into is the java.lang.OutOfMemoryError: bitmap size exceeds VM budget error (on my emulator. It works terrific on my Galaxy Tab). I understand that this means I am using too many bitmaps of large sizes without recycling them, however I am having difficulty figuring out the best place to recycle them, since each tab remains running in the background when another tab is selected.

Do I need to change my Gallery adapter to only have a few bitmaps loaded at once (such as the selected, left, and right views), or is there a simpler solution (for example, a good place to call recycle())?

Edit:
I tried using this code, and called it when a new gallery item is selected. It worked at first, but then the app still crashed. Am I not calling recycle() correctly?

/* *
 * Set the current, left, and right view's images. Set all others to NULL and recycle them.
 */
public void refreshImages() {
    for (int i = 0; i < adapter.getCount(); i++) {
        View v = adapter.getView(i, null, null);
        ImageView img = (ImageView) v.findViewById(R.id.add_image);
        Thing mything = adapter.getThing(i);//returns a Thing object at this position in the gallery.
        if (i == currentGalleryPosition //This is set when the gallery item is selected.
         || i == (currentGalleryPosition - 1) 
         || i == (currentGalleryPosition + 1)) {
            img.setImageBitmap(thing.getImage(this)); //This retrieves the bitmap from my drawable resources.
            img.setScaleType(ImageView.ScaleType.FIT_XY);
        }
        else {
            Bitmap bmp = thing.getImage();
            img.setImageBitmap(null);
            bmp.recycle();
        }
    }
}
  • 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-26T09:43:43+00:00Added an answer on May 26, 2026 at 9:43 am

    This is not the best solution, but it does what I need it to do:

    When decoding a bitmap, set the inPurgeable and inInputShareable options to true. This makes it so that if the VM needs more space, it can simply remove images (purge), but if you are sharing multiple images amongst multiple tabs, the inInputShareable option allows the decoder to simply share the same location in memory, without creating a new instance of the same bitmap.

    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inDither = true;
    o.inPurgeable = true;
    o.inInputShareable = true;
    return BitmapFactory.decodeResource(getResources(), R.drawable.img, o);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android app, I have a main activity that serves as an entry
I have an app that has a list as its main activity and then
i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int
In my main activity, I have the following code that calls my FileBrowser activity:
I have two activities: a MainListActivity, and a DetailViewActivity. DetailViewActivity is set with android:launchMode=singleTop
I have Activity A with android:launchMode=singleTop in the manifest. If I go to Activity
The main activity includes some variables with set values. I created a sub-activity with
My MAIN activity is spawning a child activity that contains a ListView . While
So I have this code in my main activity to start a new one:
For example, say the main Activity has an custom object foo with a method

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.