navigation/runtime/src/main/java/androidx/navigation/NavController.java
public boolean onHandleDeepLink(@Nullable Intent intent) {
        if (intent == null) {
            return false;
        }
        Bundle extras = intent.getExtras();
        int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
        Bundle bundle = new Bundle();
        Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
        if (deepLinkExtras != null) {
            bundle.putAll(deepLinkExtras);
        }
        if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
            Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
            if (matchingDeepLink != null) {
                deepLink = matchingDeepLink.first.buildDeepLinkIds();
                bundle.putAll(matchingDeepLink.second);
            }
        }
        if (deepLink == null || deepLink.length == 0) {
            return false;
        }
        bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
        int flags = intent.getFlags();
        if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0
                && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
            // Someone called us with NEW_TASK, but we don't know what state our whole
            // task stack is in, so we need to manually restart the whole stack to
            // ensure we're in a predictably good state.
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            TaskStackBuilder taskStackBuilder = TaskStackBuilder
                    .create(mContext)
                    .addNextIntentWithParentStack(intent);
            taskStackBuilder.startActivities();
            if (mActivity != null) {
                mActivity.finish();
            }
            return true;
        }
        if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
            // Start with a cleared task starting at our root when we're on our own task
            if (!mBackStack.isEmpty()) {
                navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                        .setPopUpTo(mGraph.getId(), true)
                        .setEnterAnim(0).setExitAnim(0).build());
            }
            int index = 0;
            while (index < deepLink.length) {
                int destinationId = deepLink[index++];
                NavDestination node = findDestination(destinationId);
                if (node == null) {
                    throw new IllegalStateException("unknown destination during deep link: "
                            + NavDestination.getDisplayName(mContext, destinationId));
                }
                node.navigate(bundle,
                        new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
            }
            return true;
        }
        // Assume we're on another apps' task and only start the final destination
        NavGraph graph = mGraph;
        for (int i = 0; i < deepLink.length; i++) {
            int destinationId = deepLink[i];
            NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            if (i != deepLink.length - 1) {
                // We're not at the final NavDestination yet, so keep going through the chain
                graph = (NavGraph) node;
            } else {
                // Navigate to the last NavDestination, clearing any existing destinations
                node.navigate(bundle, new NavOptions.Builder()
                        .setPopUpTo(mGraph.getId(), true)
                        .setEnterAnim(0).setExitAnim(0).build());
            }
        }
        return true;
    }
/**
     * Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
     * This is called automatically for you the first time you set the graph if you've passed in an
     * {@link Activity} as the context when constructing this NavController, but should be manually
     * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}.
     * <p>
     * The types of Intents that are supported include:
     * <ul>
     *     <ol>Intents created by {@link NavDeepLinkBuilder} or
     *     {@link #createDeepLink()}. This assumes that the current graph shares
     *     the same hierarchy to get to the deep linked destination as when the deep link was
     *     constructed.</ol>
     *     <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked
     *     against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol>
     * </ul>
     * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p>
     * @param intent The Intent that may contain a valid deep link
     * @return True if the navigation controller found a valid deep link and navigated to it.
     * @see NavDestination#addDeepLink(String)
     */
Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
This is called automatically for you the first time you set the graph if you've passed in an
Activity as the context when constructing this NavController, but should be manually
called if your Activity receives new Intents in  Activity#onNewIntent(Intent).

The types of Intents that are supported include:

Intents created by  NavDeepLinkBuilder or
#createDeepLink(). This assumes that the current graph shares
the same hierarchy to get to the deep linked destination as when the deep link was
constructed.
Intents that include a  Intent#getData() data Uri. This Uri will be checked
against the Uri patterns added via  NavDestination#addDeepLink(String).

The  #getGraph() navigation graph should be set before calling this method.
@param intent The Intent that may contain a valid deep link
@return True if the navigation controller found a valid deep link and navigated to it.
Checks the given Intent for a Navigation deep link and navigates to the deep link if present . This is called automatically for you the first time you set the graph if you ' ve passed in an Activity as the context when constructing this NavController but should be manually called if your Activity receives new Intents in Activity#onNewIntent ( Intent ) . The types of Intents that are supported include : Intents created by NavDeepLinkBuilder or #createDeepLink () . This assumes that the current graph shares the same hierarchy to get to the deep linked destination as when the deep link was constructed . Intents that include a Intent#getData () data Uri . This Uri will be checked against the Uri patterns added via NavDestination#addDeepLink ( String ) . The #getGraph () navigation graph should be set before calling this method . @param intent The Intent that may contain a valid deep link @return True if the navigation controller found a valid deep link and navigated to it .
public boolean onHandleDeepLink(@Nullable Intent intent) {
        if (intent == null) {
            return false;
        }
        Bundle extras = intent.getExtras();
        int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
        Bundle bundle = new Bundle();
        Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
        if (deepLinkExtras != null) {
            bundle.putAll(deepLinkExtras);
        }
        if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
            Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
            if (matchingDeepLink != null) {
                deepLink = matchingDeepLink.first.buildDeepLinkIds();
                bundle.putAll(matchingDeepLink.second);
            }
        }
        if (deepLink == null || deepLink.length == 0) {
            return false;
        }
        bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
        int flags = intent.getFlags();
        if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0
                && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            TaskStackBuilder taskStackBuilder = TaskStackBuilder
                    .create(mContext)
                    .addNextIntentWithParentStack(intent);
            taskStackBuilder.startActivities();
            if (mActivity != null) {
                mActivity.finish();
            }
            return true;
        }
        if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
            if (!mBackStack.isEmpty()) {
                navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                        .setPopUpTo(mGraph.getId(), true)
                        .setEnterAnim(0).setExitAnim(0).build());
            }
            int index = 0;
            while (index < deepLink.length) {
                int destinationId = deepLink[index++];
                NavDestination node = findDestination(destinationId);
                if (node == null) {
                    throw new IllegalStateException("unknown destination during deep link: "
                            + NavDestination.getDisplayName(mContext, destinationId));
                }
                node.navigate(bundle,
                        new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
            }
            return true;
        }
        NavGraph graph = mGraph;
        for (int i = 0; i < deepLink.length; i++) {
            int destinationId = deepLink[i];
            NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            if (i != deepLink.length - 1) {
                graph = (NavGraph) node;
            } else {
                node.navigate(bundle, new NavOptions.Builder()
                        .setPopUpTo(mGraph.getId(), true)
                        .setEnterAnim(0).setExitAnim(0).build());
            }
        }
        return true;
    }
public boolean onHandleDeepLink ( @ Nullable Intent intent ) { if ( intent == null ) { return false ; } Bundle extras = intent . getExtras ( ) ; int [ ] deepLink = extras != null ? extras . getIntArray ( KEY_DEEP_LINK_IDS ) : null ; Bundle bundle = new Bundle ( ) ; Bundle deepLinkExtras = extras != null ? extras . getBundle ( KEY_DEEP_LINK_EXTRAS ) : null ; if ( deepLinkExtras != null ) { bundle . putAll ( deepLinkExtras ) ; } if ( ( deepLink == null || deepLink . length == 0 ) && intent . getData ( ) != null ) { Pair < NavDestination , Bundle > matchingDeepLink = mGraph . matchDeepLink ( intent . getData ( ) ) ; if ( matchingDeepLink != null ) { deepLink = matchingDeepLink . first . buildDeepLinkIds ( ) ; bundle . putAll ( matchingDeepLink . second ) ; } } if ( deepLink == null || deepLink . length == 0 ) { return false ; } bundle . putParcelable ( KEY_DEEP_LINK_INTENT , intent ) ; int flags = intent . getFlags ( ) ; if ( ( flags & Intent . FLAG_ACTIVITY_NEW_TASK ) != 0 && ( flags & Intent . FLAG_ACTIVITY_CLEAR_TASK ) == 0 ) { intent . addFlags ( Intent . FLAG_ACTIVITY_CLEAR_TASK ) ; TaskStackBuilder taskStackBuilder = TaskStackBuilder . create ( mContext ) . addNextIntentWithParentStack ( intent ) ; taskStackBuilder . startActivities ( ) ; if ( mActivity != null ) { mActivity . finish ( ) ; } return true ; } if ( ( flags & Intent . FLAG_ACTIVITY_NEW_TASK ) != 0 ) { if ( ! mBackStack . isEmpty ( ) ) { navigate ( mGraph . getStartDestination ( ) , bundle , new NavOptions . Builder ( ) . setPopUpTo ( mGraph . getId ( ) , true ) . setEnterAnim ( 0 ) . setExitAnim ( 0 ) . build ( ) ) ; } int index = 0 ; while ( index < deepLink . length ) { int destinationId = deepLink [ index ++ ] ; NavDestination node = findDestination ( destinationId ) ; if ( node == null ) { throw new IllegalStateException ( "unknown destination during deep link: " + NavDestination . getDisplayName ( mContext , destinationId ) ) ; } node . navigate ( bundle , new NavOptions . Builder ( ) . setEnterAnim ( 0 ) . setExitAnim ( 0 ) . build ( ) ) ; } return true ; } NavGraph graph = mGraph ; for ( int i = 0 ; i < deepLink . length ; i ++ ) { int destinationId = deepLink [ i ] ; NavDestination node = i == 0 ? mGraph : graph . findNode ( destinationId ) ; if ( node == null ) { throw new IllegalStateException ( "unknown destination during deep link: " + NavDestination . getDisplayName ( mContext , destinationId ) ) ; } if ( i != deepLink . length - 1 ) { graph = ( NavGraph ) node ; } else { node . navigate ( bundle , new NavOptions . Builder ( ) . setPopUpTo ( mGraph . getId ( ) , true ) . setEnterAnim ( 0 ) . setExitAnim ( 0 ) . build ( ) ) ; } } return true ; }
Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
Checks the given Intent for a Navigation deep link and navigates to the deep link if present .
// Someone called us with NEW_TASK, but we don't know what state our whole // task stack is in, so we need to manually restart the whole stack to // ensure we're in a predictably good state. // Start with a cleared task starting at our root when we're on our own task // Assume we're on another apps' task and only start the final destination // We're not at the final NavDestination yet, so keep going through the chain // Navigate to the last NavDestination, clearing any existing destinations