Java tutorial
//package com.java2s; //License from project: Open Source License import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import java.util.Stack; public class Main { public static void addFragmentStacked(FragmentManager fragmentManager, Fragment fragment, int frameId, String fragmentTag, Stack<Fragment> fragmentStack) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment, fragmentTag); fragmentStack.lastElement().onPause(); transaction.hide(fragmentStack.lastElement()); fragmentStack.push(fragment); transaction.commit(); } }