miércoles, 29 de enero de 2014

Android: Add and remove fragment from back stack

In this example the activity adds the fragment and the fragment removes itself.

Add to back stack

activity.getSupportFragmentManager().beginTransaction()
.replace(R.id.main_activity_content, userProfileFragment)
.addToBackStack(UserProfileFragment.BACK_STACK_NAME)
.commit();

Remove from back stack

getMainActivity().getSupportFragmentManager()
.popBackStackImmediate(UserProfileFragment.BACK_STACK_NAME,

FragmentManager.POP_BACK_STACK_INCLUSIVE);

No hay comentarios:

Publicar un comentario