int fragmentCount = getSupportFragmentManager().getBackStackEntryCount();
if (getSupportFragmentManager().getBackStackEntryAt(fragmentCount - 1).getName().equals("LocationSearch")) {
getSupportFragmentManager().popBackStack();
} else {
clearStack();
}
}
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_bottom,
R.anim.slide_up_from_bottom);
fragmentTransaction.replace(R.id.secondarycontent_frame,
locationSearchFragment);
fragmentTransaction.addToBackStack("LocationSearch");
fragmentTransaction.commit();