I wonder if there's a way to add a fragment into the backstack just behind the showing fragment. So that when a user press "back button" the added fragment would show up to the user.
            Asked
            
        
        
            Active
            
        
            Viewed 370 times
        
    1
            
            
        - 
                    FragmentManager not contains such methods. Why you can't catch onBackPressed and show desired fragment when current closed? – Dmitry_L Nov 03 '14 at 08:55
1 Answers
0
            
            
        As per my knowledge I am not sure the Fragment Manager can do such things !
Step-1: Why don't you add the fragment tobackStack` when mounting the fragment to the container
Step-2: Next onBackpressedor click of any view just pop the fragment from the container
Here is a sample from another Stackoverflow answer
fragmentTransaction.addToBackStack("fragB");
fragmentTransaction.addToBackStack("fragC");
Then in Fragment_C, pop the back stack using the name ie.. fragB and include POP_BACK_STACK_INCLUSIVE
    someButtonInC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fm = getActivity()
                    .getSupportFragmentManager();
            fm.popBackStack ("fragB", FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    });
 
     
    