navigation/runtime/src/main/java/androidx/navigation/Navigation.java
@NonNull
    public static NavController findNavController(@NonNull Activity activity, @IdRes int viewId) {
        View view = ActivityCompat.requireViewById(activity, viewId);
        NavController navController = findViewNavController(view);
        if (navController == null) {
            throw new IllegalStateException("Activity " + activity
                    + " does not have a NavController set on " + viewId);
        }
        return navController;
    }
/**
     * Find a {@link NavController} given the id of a View and its containing
     * {@link Activity}. This is a convenience wrapper around {@link #findNavController(View)}.
     *
     * <p>This method will locate the {@link NavController} associated with this view.
     * This is automatically populated for the id of a {@link NavHost} and its children.</p>
     *
     * @param activity The Activity hosting the view
     * @param viewId The id of the view to search from
     * @return the {@link NavController} associated with the view referenced by id
     * @throws IllegalStateException if the given viewId does not correspond with a
     * {@link NavHost} or is not within a NavHost.
     */
Find a  NavController given the id of a View and its containing
Activity. This is a convenience wrapper around  #findNavController(View).

This method will locate the  NavController associated with this view.
This is automatically populated for the id of a  NavHost and its children.

@param activity The Activity hosting the view
@param viewId The id of the view to search from
@return the  NavController associated with the view referenced by id
@throws IllegalStateException if the given viewId does not correspond with a
NavHost or is not within a NavHost.
Find a NavController given the id of a View and its containing Activity . This is a convenience wrapper around #findNavController ( View ) . This method will locate the NavController associated with this view . This is automatically populated for the id of a NavHost and its children . @param activity The Activity hosting the view @param viewId The id of the view to search from @return the NavController associated with the view referenced by id @throws IllegalStateException if the given viewId does not correspond with a NavHost or is not within a NavHost .
@NonNull
    public static NavController findNavController(@NonNull Activity activity, @IdRes int viewId) {
        View view = ActivityCompat.requireViewById(activity, viewId);
        NavController navController = findViewNavController(view);
        if (navController == null) {
            throw new IllegalStateException("Activity " + activity
                    + " does not have a NavController set on " + viewId);
        }
        return navController;
    }
@ NonNull public static NavController findNavController ( @ NonNull Activity activity , @ IdRes int viewId ) { View view = ActivityCompat . requireViewById ( activity , viewId ) ; NavController navController = findViewNavController ( view ) ; if ( navController == null ) { throw new IllegalStateException ( "Activity " + activity + " does not have a NavController set on " + viewId ) ; } return navController ; }
Find a {@link NavController} given the id of a View and its containing
 {@link Activity}.
Find a { @link NavController } given the id of a View and its containing { @link Activity } .