Reputation: 2325
Where am i going wrong. I just want to check if the fragment with the given ProductId is already available in the BackStack;
If yes than dont add the new Fragment otherwise add the current fragment to the backstack.
public void showThisFragment(Fragment newFragment,int productId){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.am_fragment_holder, newFragment);
if(fragmentManager.findFragmentByTag(productId+"")==null){
fragmentTransaction.addToBackStack(productId+"");
}else{
//TODO fragment already present
//So dont add to the back stack
}
fragmentTransaction.commit();
}
please help!
Upvotes: 2
Views: 1303
Reputation: 2836
There is no tag added to replaced fragment. You should use three argument replace method. I did not test it so tell me if I am right.
fragmentTransaction.replace(R.id.am_fragment_holder, newFragment, String.valueOf(productId));
Upvotes: 1