Get Backstack status using android navigation component : <p>I want to implement backpress behaviour such that it prompts a confirmation popup when you press back with the backstack empty, otherwise it pops the next fragment in the stack.</p>

<p>I'm trying to get the backstack count, but i always get 0 from both fragment managers</p>

<pre><code> getSupportFragmentManager().getBackStackEntryCount();
 getFragmentManager().getBackStackEntryCount();
</code></pre>

<p>I guess it should work since i checked the google code of fragment navigator and it adds to backstack through the canonical fragment transaction:</p>

<p>FragmentNavigator.java:</p>

<pre><code> if (initialNavigation || isClearTask) {
        backStackEffect = BACK_STACK_DESTINATION_ADDED;
    } else if (isSingleTopReplacement) {
        // Single Top means we only want one instance on the back stack
        if (mBackStack.size() &gt; 1) {
            // If the Fragment to be replaced is on the FragmentManager's
            // back stack, a simple replace() isn't enough so we
            // remove it from the back stack and put our replacement
            // on the back stack in its place
            mFragmentManager.popBackStack();
            ft.addToBackStack(Integer.toString(destId));
            mIsPendingBackStackOperation = true;
        }
        backStackEffect = BACK_STACK_UNCHANGED;
    } else {
        ft.addToBackStack(Integer.toString(destId));
        mIsPendingBackStackOperation = true;
        backStackEffect = BACK_STACK_DESTINATION_ADDED;
    }
    ft.setReorderingAllowed(true);
    ft.commit();
</code></pre>

<p>I didn't find any API to retrieve this information through NavController or Navigator neither.</p>

<p>Thanks</p>
