We have an Activity that contains SlidingMenu ( https://github.com/jfeinstein10/SlidingMenu ), in which there are three options, call them A, B1, C1, They correspond to the fragments that we show in the Activity. When you select another option from SlidingMenu, I replace the current fragment with a new one using the FragmentManager.
From fragment B1 you can go to the other two, name them B2 and B3. Here we want the back key to take you from B2 β B1 or from B3 β B1, so I call transaction.addToBackStack (null). If we select an option from SlidingMenu when you are on B2 or B3, we want to clear the back stack, so I use the code suggested in this question to Clear the stack using fragments that popBackStack () calls until it is cleared.
So far so good.
From fragment C1, you can go to fragment C2. Since C1 / C2 have more Master / Detail design, I use
fragmentTransaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left, R.animator.slide_in_from_left, R.animator.slide_out_to_right);
to add a slide animation where C1 slides to the left, as C2 slides to the right, and vice versa. Pressing the back key while turning on C2 brings us back to C1, with reverse animation, and all is well.
BUT
If you select A or B1 from SlidingMenu, and we popBackStack () to get rid of C1 from the back stack, it shifts C2 to the right, which looks strange. What I would like to do is clear the back stack without starting the animation, but I cannot find a way to do this. I tried calling popBackStackImmediate () instead, but that does not seem to make any difference.
As an alternative, I assume that I could not call addToBackStack at all, but instead manually process the user by pressing the Back key through Activity.onBackPressed (), but maybe there is a solution that I just donβt see?
android android-fragments slidingmenu
Jonathan Caryl Apr 26 '13 at 12:08 on
source share