navigation/runtime/src/main/java/androidx/navigation/NavController.java
@Nullable
    public Bundle saveState() {
        Bundle b = null;
        if (mGraphId != 0) {
            b = new Bundle();
            b.putInt(KEY_GRAPH_ID, mGraphId);
        }
        ArrayList<String> navigatorNames = new ArrayList<>();
        Bundle navigatorState = new Bundle();
        for (Map.Entry<String, Navigator<? extends NavDestination>> entry :
                mNavigatorProvider.getNavigators().entrySet()) {
            String name = entry.getKey();
            Bundle savedState = entry.getValue().onSaveState();
            if (savedState != null) {
                navigatorNames.add(name);
                navigatorState.putBundle(name, entry.getValue().onSaveState());
            }
        }
        if (!navigatorNames.isEmpty()) {
            if (b == null) {
                b = new Bundle();
            }
            navigatorState.putStringArrayList(KEY_NAVIGATOR_STATE_NAMES, navigatorNames);
            b.putBundle(KEY_NAVIGATOR_STATE, navigatorState);
        }
        if (!mBackStack.isEmpty()) {
            if (b == null) {
                b = new Bundle();
            }
            int[] backStack = new int[mBackStack.size()];
            int index = 0;
            for (NavDestination destination : mBackStack) {
                backStack[index++] = destination.getId();
            }
            b.putIntArray(KEY_BACK_STACK_IDS, backStack);
        }
        return b;
    }
/**
     * Saves all navigation controller state to a Bundle.
     *
     * <p>State may be restored from a bundle returned from this method by calling
     * {@link #restoreState(Bundle)}. Saving controller state is the responsibility
     * of a {@link NavHost}.</p>
     *
     * @return saved state for this controller
     */
Saves all navigation controller state to a Bundle.
State may be restored from a bundle returned from this method by calling
#restoreState(Bundle). Saving controller state is the responsibility
of a  NavHost.

@return saved state for this controller
Saves all navigation controller state to a Bundle . State may be restored from a bundle returned from this method by calling #restoreState ( Bundle ) . Saving controller state is the responsibility of a NavHost . @return saved state for this controller
@Nullable
    public Bundle saveState() {
        Bundle b = null;
        if (mGraphId != 0) {
            b = new Bundle();
            b.putInt(KEY_GRAPH_ID, mGraphId);
        }
        ArrayList<String> navigatorNames = new ArrayList<>();
        Bundle navigatorState = new Bundle();
        for (Map.Entry<String, Navigator<? extends NavDestination>> entry :
                mNavigatorProvider.getNavigators().entrySet()) {
            String name = entry.getKey();
            Bundle savedState = entry.getValue().onSaveState();
            if (savedState != null) {
                navigatorNames.add(name);
                navigatorState.putBundle(name, entry.getValue().onSaveState());
            }
        }
        if (!navigatorNames.isEmpty()) {
            if (b == null) {
                b = new Bundle();
            }
            navigatorState.putStringArrayList(KEY_NAVIGATOR_STATE_NAMES, navigatorNames);
            b.putBundle(KEY_NAVIGATOR_STATE, navigatorState);
        }
        if (!mBackStack.isEmpty()) {
            if (b == null) {
                b = new Bundle();
            }
            int[] backStack = new int[mBackStack.size()];
            int index = 0;
            for (NavDestination destination : mBackStack) {
                backStack[index++] = destination.getId();
            }
            b.putIntArray(KEY_BACK_STACK_IDS, backStack);
        }
        return b;
    }
@ Nullable public Bundle saveState ( ) { Bundle b = null ; if ( mGraphId != 0 ) { b = new Bundle ( ) ; b . putInt ( KEY_GRAPH_ID , mGraphId ) ; } ArrayList < String > navigatorNames = new ArrayList < > ( ) ; Bundle navigatorState = new Bundle ( ) ; for ( Map . Entry < String , Navigator < ? extends NavDestination > > entry : mNavigatorProvider . getNavigators ( ) . entrySet ( ) ) { String name = entry . getKey ( ) ; Bundle savedState = entry . getValue ( ) . onSaveState ( ) ; if ( savedState != null ) { navigatorNames . add ( name ) ; navigatorState . putBundle ( name , entry . getValue ( ) . onSaveState ( ) ) ; } } if ( ! navigatorNames . isEmpty ( ) ) { if ( b == null ) { b = new Bundle ( ) ; } navigatorState . putStringArrayList ( KEY_NAVIGATOR_STATE_NAMES , navigatorNames ) ; b . putBundle ( KEY_NAVIGATOR_STATE , navigatorState ) ; } if ( ! mBackStack . isEmpty ( ) ) { if ( b == null ) { b = new Bundle ( ) ; } int [ ] backStack = new int [ mBackStack . size ( ) ] ; int index = 0 ; for ( NavDestination destination : mBackStack ) { backStack [ index ++ ] = destination . getId ( ) ; } b . putIntArray ( KEY_BACK_STACK_IDS , backStack ) ; } return b ; }
Saves all navigation controller state to a Bundle.
Saves all navigation controller state to a Bundle .