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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:49:05+00:00 2026-05-22T22:49:05+00:00

I finished an application recently and began profiling it for CPU & Memory usage

  • 0

I finished an application recently and began profiling it for CPU & Memory usage and came across a memory leak:

In a simple 3 tab application where each tab has a distinct function, I have a button on Tab3 which sends the user back to Tab1 along with a messageId. The activity associated with Tab1 catches this extra and displays the message if its present. See below for the button in Tab3:

public void onClick(View arg0) {
    Intent notificationIntent = new Intent(getApplicationContext(), TabContainerActivity.class);
    notificationIntent.setAction("com.test.notify.MESSAGE");
    notificationIntent.putExtra(MessageBean.MESSAGE_ID, messageId);
    startActivity(notificationIntent);
}

The tab container TabContainerActivity.class replicates Extras to child Actions. It also has logic to capture the Action sent with the intent and if one is found, it is used to decide which tab to set as current:

if(getIntent().getExtras() != null ) intent.putExtras(getIntent().getExtras());
if(getIntent().getAction().equalsIgnoreCase("com.test.notify.MESSAGE"))
{       
    tabHost.setCurrentTab(0);
}
else if(getIntent().getAction().equalsIgnoreCase("com.test.notify.SETTINGS"))
{
    tabHost.setCurrentTab(1);
}
...etc...

With the above code you can move between Tabs normally, you can also click on a message in Tab3 and have it displayed in full in Tab1 – Great! The code can easily be modified in future to allow other applications to pass MessageID’s to the first tabs activity, Wonderfu!

However – This behaviour is now in evidence:

  1. Click Tab3,
  2. Select a message
    [[ A new intent is sent, opening a new TabContainerActivity activity]]
  3. Inside this activity click Tab3,
  4. Select another message
    [[ A new intent is sent, opening ANOTHER new TabContainerActivity activity]]
  5. (Repeat 3 & 4 & 5)

Hopefully you can see the problem! You can go back through each of these activities, pealing them off the stack, but because of the recursive nature of the problem you can continue navigating, creating a new activity with each pass, to the point of OutOfMemory exceptions.

So, to the question;

I want the functionality contained inside Tab1’s activity to run whenever the Tab is made visible (In this case, loading a message) so I would like to keep it as an Activity in its own right. Saying that, when navigated to I want it to be the only Tab Activity which is on the stack. How can I achieve this?

Any help and discussion would be appreciated!

  • 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-22T22:49:05+00:00Added an answer on May 22, 2026 at 10:49 pm

    Use this

    public void onClick(View arg0) {
        Intent notificationIntent = new Intent(NotifyService.getInstance(), TabContainerActivity.class);
        notificationIntent.setAction("com.test.notify.MESSAGE");
        notificationIntent.putExtra(MessageBean.MESSAGE_ID, messageId);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(notificationIntent);
    }
    

    I think just using .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) to the intent you’re using to start the activity again will help you to get the desired result.

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

Sidebar

Related Questions

I recently came across a ASP 1.1 web application that put a whole heap
We've recently finished development of a web application that works as expected. When we
At my work we recently finished the system architecture for a control application which
I have pretty much finished my first working Symbian application, but in my hastened
I recently finished a project using TDD and I found the process to be
i recently finished one project..now when i create a new navigation project in xcode
The application I'm working on is almost finished but we've come to a crossroads.
i just finished Coding my PHP application now the coding has become somewhat Huge
I just finished a Java application to link to Sicstus prolog. Now I need
We created an application profile using our company's Facebook account. Today, I've just finished

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.