private static void changeFragment(Fragment f, boolean init) {
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.info_content, f,f.getC
It might be too late to answer this question. Hope this answer will help someone anyway.
Mostly it depends on where you are actually calling getBackStackEntryCount() method. In my case, I was calling this method after calling super.onBackPressed(). The moment this method was got called, there was no fragment in back stack. That's why I was always receiving 0.
Right way of calling the method in onBackPressed() :
@Override
public void onBackPressed() {
try {
int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
Log.d("class", "items in backstack " + backStackEntryCount);
} catch (Exception e) {
e.printStackTrace();
}
super.onBackPressed();
}