1

I am struggling to remove a single fragment that I add dynamically when I have multiple fragments.

For examples: MainActivty Inflate FragA Inflate FragB Inflate FragC

Now how do I just delete fragment A?

Using popBackStack kills all three and getSupportFragmentManager().beginTransaction().remove(TAG).commit(); also seems to do thae same thing

How are you meant to do this correctly? I am trying to keep multiple backstacks persistent over tabs

SuperBale
  • 341
  • 2
  • 8
  • 20

2 Answers2

0

try this...

get current fragment title & check fragment A or not.

get current fragment title to use getTitle() Method and check

  if(getTitle().toString.equals(fragment A){
         // do 
    }else{
         // do 
    }
Ramesh Prajapati
  • 654
  • 6
  • 10
0

Can you try this..

For eg. using fragment name as tag:

FragmentA fragment = new FragmentA();
String backStateName = fragment.getClass().getName();

Adding to backstack:

FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.addToBackStack(backStateName);
ft.commit();

Popping:

getSupportFragmentManager().popBackStackImmediate (backStateName, 0); 

This should only pop the fragment with the specific tag.

Abu Ruqaiyah
  • 1,516
  • 1
  • 12
  • 20