I want to remove middle fragment of fragment stack. i.e I have stack with Fragments A, B, C, D in this case i want to remove B or C without removed D.
Is there any way to do that? because if i remove D and re-added it after removing B or C it will take time to create view and add all details again.
Use tags while calling the fragments with each fragment having a unique tag. Then remove fragments from fragment stack by using this tag.
Switch between fragments like this:
public void switchContent(final Fragment fragment, final String TAG) {
CgUtils.showLog(TAG, "in switchcontent with fragment passed " + fragment);
mContentFragment = fragment;
Handler h = new Handler();
h.postDelayed(new Runnable() {
public void run() {
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, TAG)
.commitAllowingStateLoss();
fragment.setRetainInstance(true);
getSlidingMenu().showContent();
// .commit();
}
}, 50);
}
e.g :
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.remove(fragmentManager.findFragmentByTag(tag)).commit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With