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

The Archive Base Latest Questions

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

I have an Android Honeycomb application with two activities; the first one has a

  • 0

I have an Android Honeycomb application with two activities; the first one has a large Bitmap (taken from resources) as a background to the main LinearLayout and I have discovered that setting the background of this element to null from the activity’s onStop() method can save a lot of memory—around 5MB, in fact.

However, this only seems to work when I click the “sleep” button on the device. If I do that the profiler shows the 5MB drops out of the world as easy as you like. If I start the second activity, the first activity’s onStop() doesn’t get hit until after the second activity’s onCreate() and the profiler suggests that the BitmapDrawable is not removed from memory after all—so there it sits, five invisible useless megabytes, cluttering the place up.

I could remove this from onPause(), which might work better, but I’m also using the onStop() methods of various Dialog elements to null their background drawables as well. They don’t seem to have onPause() methods.

Is there a recommended method for getting rid of these kinds of large, memory-consuming elements as an activity launches another one?

  • 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:35:44+00:00Added an answer on May 26, 2026 at 9:35 am

    Also for me OnPause event is a better place where put your “memory-free” code.

    Here the event flow when you open a child activity from a parent activity

    -- Open caller activity -- 
    [ActCaller] 1311090884303: onCreate
    [ActCaller] 1311090884572: onStart
    [ActCaller] 1311090884699: onPostCreate savedInstanceState null
    [ActCaller] 1311090884802: onResume
    [ActCaller] 1311090884908: onPostResume
    -- Open child activity --
    [ActCaller] 1311090926270: onSaveInstanceState
    [ActCaller] 1311090926374: onPause
      [ActChild] 1311090926556: onCreate
      [ActChild] 1311090926703: onStart
      [ActChild] 1311090926807: onPostCreate savedInstanceState null
      [ActChild] 1311090926911: onResume
      [ActChild] 1311090927014: onPostResume
    [ActCaller] 1311090927508: onStop
    

    As you already noticed, parent’s onStop is called only after complete child creation.

    What about calling memory-free code from two different location? Consider that dialogs, generally, don’t completely cover calling activity, so preserving it’s background has a sense.
    Maybe a flag can be set when you open a new activity instead of a dialog, and OnPause logic will drop background only when a new activity is launched, and not a dialog.

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

Sidebar

Related Questions

I have two threads in an Android application, one is the view thread, and
I have android application with ListView, where each row has own refresh button. Refreshing
Hello I have an android application which has a service running. After 20 mins
I have an Android application for pre-Honeycomb devices that uses custom tabs to launch
I have an application without launcher activity that works properly from Android 1.5 to
I have been tasked with porting a large Java codebase to the Android platform.
I have android application and service that runs in separate process. Application and service
I have android code that uses a background process to routinely (e.g. hourly) connect
I have the android:cacheColorHint=#00000000 set on my ListView, which fixed this issue in one
I have an Android App with 2 activities. I have the following in the

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.