use the following code,
//add to back stack
transaction.addToBackStack(type.getClass().getName());
//Commit the transaction
transaction.commit();
String as parameter might help in identifying fragments
In case you don't need to identify this back stack later on, pass null for addToBackStack
.