Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FragmentManager's getBackStackEntryCount() return zero?

private static void changeFragment(Fragment f, boolean init) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.info_content, f,f.getClass().getName());
        if(!init){
            ft.addToBackStack(null);
        }
        ft.commit();
    }

when I want to get the stack cout by call fm.getBackStackEntryCount(), it returns zero?

like image 994
beiliubei Avatar asked Dec 20 '12 02:12

beiliubei


1 Answers

It might be too late to answer this question. Hope this answer will help someone anyway.

You should getBackStackEntryCount() method in onResume().

It will be this:

@Override
protected void onResume() {
    super.onResume();
    Log.i(TAG, "onResume: " + fragmentManager.getBackStackEntryCount());
    for (int entry = 0; entry < fragmentManager.getBackStackEntryCount(); entry++) {
        Log.i(TAG, "Found fragment: " + fragmentManager.getBackStackEntryAt(entry).getId());
    }
}

Good luck!

like image 156
Jason Avatar answered Sep 17 '22 21:09

Jason