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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:05:58+00:00 2026-05-28T02:05:58+00:00

I have 3 activities A, B and C. I inflate activity B dynamically on

  • 0

I have 3 activities A, B and C.

I inflate activity B dynamically on a button click and the user can add as many views as he likes.

The operation is like this:

User sees “Activity A” first enters his details and clicks the save button and I take him to “Activity B” where he adds certain fields as many times he likes and when he clicks save again I take him to “Activity C”.

Now when I am at A and go to B and add some views and enter text in TextViews and then hit save and go to C. From C if I hit back I see B intact along with all the inflated views and entered text obviously because it is saved in the Back Stack, but if I go from B to A by hitting back and then come back to B all the views are gone because it is removed from the Back Stack.

I wanted to know if it is possible to hold only one instance of B in the BackStack and not kill it at all when the user hits back?
I had overriden back key but to no avail because the activity is killed anyways, some people suggested that I should save the entire views and data from it to a Parcelable ArrayList and regenerate them again in onCreate but that doesnt look feasible to me as I think we can save it in BackStack anyway.

I came across this guide at android developers http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html which says about these activity attributes

android:taskAffinity
android:launchMode
android:allowTaskReparenting
android:clearTaskOnLaunch
android:alwaysRetainTaskState
android:finishOnTaskLaunch
android:singleTask
android:singleInstance

But I am unaware of how to put them to use.

Has anyone tried this out yet? If so please help me put the pieces together.

  • 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-28T02:05:59+00:00Added an answer on May 28, 2026 at 2:05 am

    Yes,I agree with Nandeesh.

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
                switch(keyCode)
                {
                case KeyEvent.KEYCODE_BACK:
                    //bring back the previous activity do your logic here           
                    return false; //means you don't want to remove the activity from stack 
                }
            return super.onKeyDown(keyCode, event);  // means u want to remove the last activity from Activity stack.
        }
    
        so question  is that how u can go to other activity without remove it from stack, 
        you can use  :
                    Intent myIntent = new Intent(CurrentClass.this, JumptoActivity.class);
                     startActivity(myIntent);*
    
    example: at the switch case u can use this
    
    if(KeyEvent.KEYCODE_BACK)
    {
                    Intent myIntent = new Intent(CurrentClass.this, NextActivity.class);
                     startActivity(myIntent);
                    return false;
    }
    else
        return true;       //if you not write this then your  menu and other think will be affected.
    

    Thank you I think this little bit information will be helpful for u.

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

Sidebar

Related Questions

I have 2 activities in my app and I would like activity X to
I have two activities A and B, and from activity A, I click on
I have 2 activities A->B. A is the parent activity and B is like
In our app, we have Activities A,B,C,D, and E. The user usually goes from
I have two activities; Home is my first activity and Settings is my second
I have two activities. Home activity contain a list view with two buttons named
I have seen many posts about using ActivityGroups for when you have nested activities
I have 15-20 activities in my application. I want when user clicks on the
I have two activities, one is main and I have another activity called Test
I want to be able to control which activities the user can press 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.