I have an issue in fragment navigation in android. I am navigating from one fragment to another and from that fragment to another. When I press the back button, I need to navigate from the third fragment to first fragment. I need to avoid the second fragment from backstack.
Here is the code I am using for adding fragment to FragmentManager
try {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.addToBackStack(newFragmentType.toString());
transaction.replace(R.id.fragmentContainer, newFragment,newFragmentType.toString());
transaction.commitAllowingStateLoss();
getSupportFragmentManager().executePendingTransactions();
} catch (java.lang.IllegalStateException e) {
}
Please help