navigation/runtime/src/main/java/androidx/navigation/NavController.java
public boolean popBackStack(@IdRes int destinationId, boolean inclusive) {
        if (mBackStack.isEmpty()) {
            throw new IllegalArgumentException("NavController back stack is empty");
        }
        ArrayList<NavDestination> destinationsToRemove = new ArrayList<>();
        Iterator<NavDestination> iterator = mBackStack.descendingIterator();
        while (iterator.hasNext()) {
            NavDestination destination = iterator.next();
            if (inclusive || destination.getId() != destinationId) {
                destinationsToRemove.add(destination);
            }
            if (destination.getId() == destinationId) {
                break;
            }
        }
        boolean popped = false;
        iterator = destinationsToRemove.iterator();
        while (iterator.hasNext()) {
            NavDestination destination = iterator.next();
            // Skip destinations already removed by a previous popBackStack operation
            while (!mBackStack.isEmpty() && mBackStack.peekLast().getId() != destination.getId()) {
                if (iterator.hasNext()) {
                    destination = iterator.next();
                } else {
                    destination = null;
                    break;
                }
            }
            if (destination != null) {
                popped = destination.getNavigator().popBackStack() || popped;
            }
        }
        return popped;
    }
/**
     * Attempts to pop the controller's back stack back to a specific destination.
     *
     * @param destinationId The topmost destination to retain
     * @param inclusive Whether the given destination should also be popped.
     *
     * @return true if the stack was popped at least once, false otherwise
     */
Attempts to pop the controller's back stack back to a specific destination.
@param destinationId The topmost destination to retain
@param inclusive Whether the given destination should also be popped.

@return true if the stack was popped at least once, false otherwise
Attempts to pop the controller ' s back stack back to a specific destination . @param destinationId The topmost destination to retain @param inclusive Whether the given destination should also be popped . @return true if the stack was popped at least once false otherwise
public boolean popBackStack(@IdRes int destinationId, boolean inclusive) {
        if (mBackStack.isEmpty()) {
            throw new IllegalArgumentException("NavController back stack is empty");
        }
        ArrayList<NavDestination> destinationsToRemove = new ArrayList<>();
        Iterator<NavDestination> iterator = mBackStack.descendingIterator();
        while (iterator.hasNext()) {
            NavDestination destination = iterator.next();
            if (inclusive || destination.getId() != destinationId) {
                destinationsToRemove.add(destination);
            }
            if (destination.getId() == destinationId) {
                break;
            }
        }
        boolean popped = false;
        iterator = destinationsToRemove.iterator();
        while (iterator.hasNext()) {
            NavDestination destination = iterator.next();
            while (!mBackStack.isEmpty() && mBackStack.peekLast().getId() != destination.getId()) {
                if (iterator.hasNext()) {
                    destination = iterator.next();
                } else {
                    destination = null;
                    break;
                }
            }
            if (destination != null) {
                popped = destination.getNavigator().popBackStack() || popped;
            }
        }
        return popped;
    }
public boolean popBackStack ( @ IdRes int destinationId , boolean inclusive ) { if ( mBackStack . isEmpty ( ) ) { throw new IllegalArgumentException ( "NavController back stack is empty" ) ; } ArrayList < NavDestination > destinationsToRemove = new ArrayList < > ( ) ; Iterator < NavDestination > iterator = mBackStack . descendingIterator ( ) ; while ( iterator . hasNext ( ) ) { NavDestination destination = iterator . next ( ) ; if ( inclusive || destination . getId ( ) != destinationId ) { destinationsToRemove . add ( destination ) ; } if ( destination . getId ( ) == destinationId ) { break ; } } boolean popped = false ; iterator = destinationsToRemove . iterator ( ) ; while ( iterator . hasNext ( ) ) { NavDestination destination = iterator . next ( ) ; while ( ! mBackStack . isEmpty ( ) && mBackStack . peekLast ( ) . getId ( ) != destination . getId ( ) ) { if ( iterator . hasNext ( ) ) { destination = iterator . next ( ) ; } else { destination = null ; break ; } } if ( destination != null ) { popped = destination . getNavigator ( ) . popBackStack ( ) || popped ; } } return popped ; }
Attempts to pop the controller's back stack back to a specific destination.
Attempts to pop the controller ' s back stack back to a specific destination .
// Skip destinations already removed by a previous popBackStack operation