Search..

Sunday, March 31, 2024

How to check backStack of Fragment that it is already assisted with Activity



public void checkBackStackAlreadyPresent()
{

 int fragmentCount = getSupportFragmentManager().getBackStackEntryCount();

if (fragmentCount != 0) {
if (getSupportFragmentManager().getBackStackEntryAt(fragmentCount - 1).getName().equals("LocationSearch")) {
getSupportFragmentManager().popBackStack();
} else {
clearStack();
}
}

}



public void addFragment(){

//flightDatePickerFragment = null;
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();

}

No comments:

Post a Comment