Android activity's memory management

by Mihai Dumitrache » Mon, 01 Mar 2010 22:31:01 GMT

Sponsored Links
 Hello guys,
I have a problem with my application, and it's about a Virtual memory
ERROR/AndroidRuntime(19790): java.lang.OutOfMemoryError: bitmap size
exceeds VM budget

The story is like this:
I have an activity (let's call it A), the user click on a button from
this activity, then i will make an api call somewhere in the internet,
and after the result is back i start a subactivity (let's call it B).

In the activity B i have to dinamicaly load some images from the
resources folder. I load the images into bitmaps -> drawables ->
imageviews. After the user click's on some buttons i have to
setResult(..), finish(), and get back to activity A.

The thing is that, goes from activity A to B, then B -> A, then A -> B
for a few times, my app crashes with the message above: it doesn't
have enough memory to load the interface.

I can not maintain the activity B on the stack because i don't want
the user to go to this activity without going through activity A

Do you guys have any solution for this problem ?


Android activity's memory management

by Bob Kerns » Tue, 02 Mar 2010 02:01:26 GMT

 If I'm interpreting your pattern correctly, you're invoking activity A
from activity B, and activity B from activity A?

That would explain your problem, at least.

Instead of invoking A from B -- return to A by finishing B. Then
you'll only every have one A, and at most one B active at a time.

It you can't do this, and really need that stack of A's and B's,
you'll have to figure out a way to hold onto less memory -- for
example, when B passes images to A, have it forget all about them, so
when A is done with them and invokes the next B, they can be garbage


Sponsored Links

Other Threads

1. setting alarm


This is 1:12am, not 8am.


-- Use Calendar.getInstance()
-- Do not forget that if it is after 1:12am today (which is to say,
the bulk of the day), this time will be in the past

Mark Murphy (a Commons Guy) | |

_The Busy Coder's Guide to *Advanced* Android Development_ Version
1.9.2 Available!


2. setting alarm


i am facing issues for  setting alarm through android code.
I  gone through  most of the documents  on net  about alarmmanager and
how to use it but  nothing worked.

please  find  the code am using  ,is it the right way for  setting
alarm .
i  am setting it for  8 AM morning .but  its not  working  i am
strugling on it for 3 hrs.
i am testing it on emulator.
Calendar calendar = new GregorianCalendar(); or // Calendar calendar =
new Calendar();
 calendar.set(Calendar.SECOND, 0);
 alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),

Thank  you


3. ImageView change image

4. OutofMemoryError on Thunderbolt: HttpClient.execute

5. Low latency audio

6. Monkeyrunner error for device

7. ImageView setColorFilter, what to do for a bitmap?