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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:37:22+00:00 2026-06-17T06:37:22+00:00

Why does FragmentTwo disappear from the backstack in the following situation: My app has

  • 0

Why does FragmentTwo disappear from the backstack in the following situation:

  • My app has a Fragment called FragmentOne in an Activity.
  • FragmentOne holds a Button. When clicked, it launches FragmentTwo, which is added to the Fragment backstack.
  • FragmentTwo has a Button, which when clicked adds two tabs to the ActionBar linked to two Fragments, FragmentThree and FragmentFour. FragmentThree is visible.
  • If I now click the back button, I expected to see FragmentTwo. Instead, I see FragmentOne. Where did FragmentTwo go?

Before I override onKeyDown() and start implementing my own backstack for Fragments I wanted to ask if there is something obvious I am missing? Note there is no configuration change happening when testing this.

enter link description here

Details:

FragmentOne’s button click handler contains:

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    FragmentTwo fragment = new FragmentTwo();
    ft.addToBackStack(null);
    ft.replace(android.R.id.content, fragment).commit();

FragmentTwo button click is handled in the Activity:

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    FragmentFour fragmentThree = new FragmentThree();
    FragmentFive fragmentFive = new FragmentFive();

    ActionBar.Tab tab = getActionBar().newTab().setText("Frag 3").setTabListener(new CustomTabListener<FragmentThree>(fragmentThree));
    getActionBar().addTab(tab);
    tab = getActionBar().newTab().setText("Frag 4").setTabListener(new CustomTabListener<FragmentFour>(fragmentFour));
    getActionBar().addTab(tab);

where the tab listener is:

public static class CustomTabListener<T extends Fragment> implements TabListener {
    Fragment fragment;

    public CustomTabListener(Fragment fragment) {
        this.fragment = fragment;
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(android.R.id.content, fragment);
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {

    }
}

I if add more Fragments to backstack before FragmentThree is shown, it is always and only the Fragment immediately before FragmentThree that has disappeared.

When I leave the Tabbed user view by pressing the back key and return to FragmentOne, the tabs are still showing. I understand I need to reset the ActionBar to NAVIGATION_MODE_STANDARD, but it’s not clear why FragmentOne is showing instead of FragmentTwo.

  • 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-17T06:37:23+00:00Added an answer on June 17, 2026 at 6:37 am

    I think the problem is if you build your tabs

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(android.R.id.content, fragment);
    }
    

    gets called and the fragment before is not added to the backstack

    did you try to call

    ft.addToBackStack(null);
    

    in the Fragment Two button handling code.

    But you need to implement onBackPressed() anyway to get rid of the tabs. I think I would make new activity with tabs.

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

Sidebar

Related Questions

Does anyone have any good information aside from the Google App Engine docs provided
Does anyone know how to call google play from web to install an app
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
Does the following psuedo code accomplish my goal of cleaning up after myself when
Does the following code in C have defined behavior? int main() { const int
Does anybody know if Python has an equivalent to Java's SortedSet interface? Heres what
Does this code get called for every object creation in Java, because every object
Does anyone know how to change the iPhone settings for an app? For example
Does anybody know a way to create a keyboard shortcut for the button 'Expand
Does anyone know how to add a generic principal to the HTTPContext from 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.