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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:11:07+00:00 2026-06-15T12:11:07+00:00

Does the Back Stack support interaction with nested Fragments in Android? If it does,

  • 0

Does the Back Stack support interaction with nested Fragments in Android?

If it does, what am I doing wrong? In my implementation, the back button is completely ignoring the fact that I added this transaction to the back stack. I’m hoping it is not because of an issue with nested fragments and just me doing something incorrectly.

The following code is inside of one of my fragments and is used to swap a new fragment with whatever nested fragment is currently showing:

     MyFragment fragment = new MyFragment();
     FragmentTransaction ft = getChildFragmentManager().beginTransaction();
     ft.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_left, R.animator.slide_in_from_left, R.animator.slide_out_right);
     ft.addToBackStack(null);
     ft.replace(R.id.myFragmentHolder, fragment);
     ft.commit();
  • 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-15T12:11:08+00:00Added an answer on June 15, 2026 at 12:11 pm

    I have the same problem, I would like to nest fragments, and to keep a back stack for each nested fragment.

    But… it seems that this case is not handled by the v4 support library. In the FragmentActivity code in the library, I can find :

    public void onBackPressed() {
        if (!mFragments.popBackStackImmediate()) {
            finish();
        }
    }
    

    The mFragments represents the FragmentManager of the activity, but it does not seem this manager “propagates” the pop to children managers.
    A workaround would be to manually call the popBackStackImmediate() on the child manager, like this in the activity inherited from FragmentActivity :

    private Fragment myFragmentContainer;
    
        @Override
        public void onBackPressed() {
                if (!myFragmentContainer.getChildFragmentManager().popBackStackImmediate()) {
                    finish(); //or call the popBackStack on the container if necessary
                }
        }
    

    There might be a better way, and a more automated way, but for my needs it is allright.

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

Sidebar

Related Questions

Does anyone know if there's a Flash (ActionScript) library for providing back button support?
customers does not want to allow user to use back or forward button. Just
I have ViewControllers A and B on the navigation stack. A does not support
Does anyone know how to modify fbauth:// parameters to effect a redirect back to
Does TortoiseSVN Revision Graph draw a line from Branch back to the Trunk when
Using .NET's Office interop libraries, does anybody know the best way to convert back
I came across this code just few minutes back here in Stack Overflow. I
Read a question on stack overflow sometime back with the following syntax In [1]:
after looking up the 'Defining launch modes' section of the 'Tasks and Back Stack'
I want to have a method called when the user clicks the back button

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.