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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:36:32+00:00 2026-05-31T06:36:32+00:00

I have 4 Different Activities, and going through the links I have created a

  • 0

I have 4 Different Activities, and going through the links I have created a Sample for the same.

Objective:

Activities A,B,C,D;

A -> B -> C -> D

An event in D causes C and D to pop Leaving A and B in stack.

An event in D may cause B C and D to POP leaving only A in stack.

Implementation:

I use the following Event for my First Three Activities i.e. A B C

if(v==buttonNext){
        Intent secondAct=new Intent(FirstActivity.this, SecondActivity.class);
        //storing the Stack
         MaintainMyStack.addBackActivity(this); 
        startActivity(secondAct);
    }

I use the following Event for my Forth Act. i.e. D

if(v==btnBack){
        finish();//finishes  "D"
        Activity act=MaintainMyStack.getBackActivity();

        act.finish(); //finishes last in stack i.e. "C"
    }

I use this Common Class Amongst My A B C D Activities.

public class MaintainMyStack  {
    private static Stack<Activity> classes = new Stack<Activity>();

    public static Activity getBackActivity() {
    return classes.pop();
    }
    public static void addBackActivity(Activity c) {
    classes.push(c);
    }
}

It works as desired, but I am just concerned about the MaintainMyStack class might Leak Memory when it meets real Scenerio, Please suggest should I go with this approach or Do we have other options to implement the same.
How can i create the MaintainMyStack have just one instance without leaking any memory

  • 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-31T06:36:33+00:00Added an answer on May 31, 2026 at 6:36 am

    You should have a look at the Intents flag FLAG_ACTIVITY_CLEAR_TOP. Adding this flag to your Intent will do exactly what you are trying to achieve with your own activity stack, and you won’t need that anymore.

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

Sidebar

Related Questions

I have a database that will store events. Each event has different activities. The
I have different Activities where the catch{} block mostly should do the same, eg.
I have three different activities sharing exactly the same layout (a ListView and a
Assume that we have 3 different activities. Each activity has its own XML file
I have a handler and I have to send responses to different activities for
I have a tabActivity which has 3 tabs and 3 different activities in each
I have different urls that points to the same code www.url1.com www.url2.com I need
I have two functions that have different enough logic but pretty much the same
In my app, I have different activities with listviews. The datas come from a
In my application, I have two different activities and both are list activities. I

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.