Reputation: 8495
Say i have fragment's A,B,C and D. The normal movement between fragments is A -> B -> C -> D. Now suppose i want to jump from A -> D, but onBackPressed() from D i want to be able to navigate back to C and then B respectively. Is there a way of doing this? The code i was attempting was something like this but it ucrrently is not working.
public void showNestedFragment(LinkedList<Fragment> fragments, boolean allowBack)
{
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (allowBack == false) // pop all thats in the backstack
getSupportFragmentManager()
.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
for(Fragment fragment : fragments){
fragmentTransaction.add(R.id.fragment, fragment);
if (allowBack)
{
fragmentTransaction.addToBackStack(null);
}
try
{
fragmentTransaction.commit();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
}
}
Upvotes: 1
Views: 101
Reputation: 5263
You have fragments so you can do anything you want. You should follow these steps to achieve this.
Upvotes: 1