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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:04:03+00:00 2026-06-08T09:04:03+00:00

We’ve been developing an application that has a drop down dashboard that allows the

  • 0

We’ve been developing an application that has a drop down dashboard that allows the users to navigate throughout the app. The navigation is not very standard since this menu can be accessed from almost every activity.
After playing for a while opening activities using the menu, the stack starts to grow and grow.

All these activities contain listviews with several imageviews inside, and they take around 3mb each. If the user plays enough and creates more than 25 activities on the stack this is what happens:

  1. Out of memory error is thrown (Heap is increased till there’s no more heap).
  2. A dialog is shown due to the exception (Unfortunately, %activity% has stopped.)
  3. The activity where the outofmemerror was thrown is finished.
  4. All the activities in the stack are finished, but the history is kept, so its possible to backup and each activity is recreated automaticall by the OS.

I was expecting the system to kill the oldest activities in the stack automatically BEFRORE the OutOfMemoryError was thrown…

Just to be sure the OS is not killing old activities, I created a test app that allocates 1mb each time. Guess what: The behavior is the same and outofmemerror is thrown:

The question is: How can we tell the Android OS that it is allowed to deallocate activities and its resources if needed so we don’t get the “Unfortunately, your activity has stopped.” dialog?

Proof of concept

    package com.gaspar.memorytest;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MemoryTestActivity extends Activity { /** Called when the activity is first created. */ private byte[] mData; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); ((Button)findViewById(R.id.button)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(MemoryTestActivity.this, MemoryTestActivity.class); startActivity(i); } }); mData = new byte[1*1024*1024]; } }

  • 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-08T09:04:05+00:00Added an answer on June 8, 2026 at 9:04 am

    I was expecting the system to kill the oldest activities in the stack automatically BEFRORE the OutOfMemoryError was thrown

    Android does not do this. Android terminates processes to free up system memory for other processes. It does not get involved with intra-app memory usage in a similar fashion.

    How can we tell the Android OS that it is allowed to deallocate activities and its resources if needed so we don’t get the “Unfortunately, your activity has stopped.” dialog?

    You can’t.

    Instead, you need to design your application to use fewer activities, or use fewer resources per activity. For example, you can “recycle” existing activity instances via FLAG_ACTIVITY_REORDER_TO_FRONT, or (as Mr. Tornquist pointed out), you can finish() activities manually yourself.

    After playing for a while opening activities using the menu, the stack starts to grow and grow.

    You should probably be using FLAG_ACTIVITY_REORDER_TO_FRONT on these menu items, so that you bring the existing activity forward in the task, rather than creating new ones each time.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into

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.