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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:30:17+00:00 2026-05-28T13:30:17+00:00

Activity 1 is visible. Press a button, and Activity 2 opens. Activity 2 adds

  • 0
  1. Activity 1 is visible. Press a button, and Activity 2 opens.
  2. Activity 2 adds fragment A to itself (and back stack) and it displays fine
  3. Pressing a button within the fragment transitions to another fragment, B
  4. Press Back. Nothing happens. Huh? The Back press is seemingly absorbed and not acted upon, the display remains the same.
  5. Press Back a second time, it reverts to the Activity 1, as expected.

Why is my fragment not being shown in step 4? I’ve added the fragment to the back stack, so why (when the Back button seems aware of its existence) does it not show the fragment?

Here’s the code I’m using in Activity 2 to open Fragment A.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.act_profile_edit);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.addToBackStack(null);
    transaction.add(android.R.id.content, new MyFragment());
    transaction.commit();
}

And here’s the code to open Fragment B

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.add(android.R.id.content, new MyOtherFragment());
    transaction.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-05-28T13:30:17+00:00Added an answer on May 28, 2026 at 1:30 pm

    Have you tried transaction.replace(...) instead of transaction.add(...)? That should work. I’m guessing because if you’re just adding a fragment over another, it doesn’t see transaction as wanting to go back fro Fragment A.

    EDIT
    The actual answer for the question is below in the comments: addToBackStack() should be used on the fragment which is replacing, not the one being replaced.

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

Sidebar

Related Questions

On pressing the back button, I'd like my application to go into the stopped
An activity has a Button and a ListView. Initially, only the Button is visible.
Sampling with Activity Monitor/Instruments/Shark will show stack traces full of C functions for the
How can I know the visible size of my activity? I'm trying to get
How would I ask the current activity for a list of any ProgressDialog's visible
I have an Activity A, and there is a button B in the view.
My activity is panned in order to make space for soft keyboard(keyboard is visible).
I have an activity that starts a long-running service which in turn adds an
I am launching an activity which displays a ListView. When an item is selected
I have 3 activities. 1st activity has a 'go right' image button. (to move

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.