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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:27:23+00:00 2026-06-06T19:27:23+00:00

I push a fragment on the fragment stack using the following code: FragmentManager fragmentManager

  • 0

I push a fragment on the fragment stack using the following code:

FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right,
     R.anim.slide_in_left, R.anim.slide_out_left);
fragmentTransaction.replace(getId(), newFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

This way, when the fragment stack is popped, e.g. by pressing the back button, a fragment pop animation is played. However, there are situations in which i would like to pop the fragment backstack without showing this animation, e.g. because I just returned from another activity and want to display the previous fragment at once, without animation.

An example navigation could look like this:

  • The user is on the start screen with the root fragment
  • He selects an item on the root fragment which then displays a new fragment to show details of that item. It does so using a fragment transaction that sets animations both for the push and the pop case (so when the user presses the back button, the transition is animated)
  • From this fragment he starts an activity which (for whatever reason) deletes the item that was just shown
  • When this activity finishes, I would like to return to the root fragment without showing the “pop animation” of the “detail fragment”

Is there a way to pop the fragment backstack without playing the specified pop animation?

  • 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-06T19:27:25+00:00Added an answer on June 6, 2026 at 7:27 pm

    So Warpzit was on the right track, he just didn’t address your specific issue too well. I came across the exact same issue and here is how I solved it.

    First I created a static boolean variable (for simplicity’s sake, lets put it in the FragmentUtils class)…

    public class FragmentUtils {
        public static boolean sDisableFragmentAnimations = false;
    }
    

    Then, in EVERY fragment you have, you need to override the onCreateAnimation method…

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        if (FragmentUtils.sDisableFragmentAnimations) {
            Animation a = new Animation() {};
            a.setDuration(0);
            return a;
        }
        return super.onCreateAnimation(transit, enter, nextAnim);
    }
    

    Then, when you need to clear the backstack from your activity simply do the following…

    public void clearBackStack() {
        FragmentUtils.sDisableFragmentAnimations = true;
        getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        FragmentUtils.sDisableFragmentAnimations = false;
    }
    

    And voila, a call to clearBackStack() will drop you back into the root fragment without any transition animations.

    Hopefully the big G will add a less stupid way of doing this in the future.

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

Sidebar

Related Questions

I have the following code fragment #include <iostream> #include <ostream> #include <vector> using namespace
I implemented push notifications using APNS-PHP http://code.google.com/p/apns-php/ on my server. I now have to
Would someone please take a look at the following code fragments (all from one
push scene by tapping on image. i am using one image when i am
I am trying to apply RotateTransform to a Rect object with the following code.
When I try an push to my remote repo (Unfuddle) using TortoiseGit, my favourite
while i'm using push notification in iphone with local server(used php), not able to
G'day, Why am I getting the following two errors from the script fragment below?
I have three questions based on the following code fragments I have a list
I push my Futures from a ExecutorService into a hash map. Later, I may

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.