I have a Parent Fragment
containing a Child Fragment
which displays some data.
At some point the Child Fragment broadcasts that the user is finished (that there is no data to be displayed). At this point I want to remove this useless fragment but I somehow don't success. Am I missing something?
The way I add the fragment to the container (and it works really good):
if (swipeFragment == null)
swipeFragment = new SwipeViewFragment();
if (getActivity() != null) {
getChildFragmentManager().beginTransaction().add(R.id.jobSearchContainer, swipeFragment, "swipe").commitAllowingStateLoss();
status = SWIPE;
}
The way I planed to remove it (but it doesn't work and it is all the variations I tried):
Fragment swipe = getChildFragmentManager().findFragmentByTag("swipe");
if (swipe == null){
throw new RuntimeException("Nope");
}
getChildFragmentManager().beginTransaction().remove(swipe).commit();
getChildFragmentManager().beginTransaction().hide(swipe).commit();
getChildFragmentManager().popBackStack();
getFragmentManager().beginTransaction().remove(swipe).commit();
I am missing something?
Thanks
PS: When I say that it doesn't work: I mean the fragment is not getting removed and I have no output in logcat
UPDATE
Fragment swipe = getChildFragmentManager().findFragmentByTag("swipe");
if (swipe == null){
throw new RuntimeException("Nope");
}
Log.d("DEBUG", ""+getChildFragmentManager().getFragments().size());
getChildFragmentManager().beginTransaction().remove(swipe).commit();
getChildFragmentManager().popBackStack();
Log.d("DEBUG", ""+getChildFragmentManager().getFragments().size());
Has for a result:
1
1