# Navigation

Artifact: [androidx.navigation:navigation-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/Navigation.+class:androidx.navigation.Navigation) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

*** ** * ** ***


```
public static class Navigation
```

<br />

*** ** * ** ***

Entry point for navigation operations.

This class provides utilities for finding a relevant `https://developer.android.com/reference/androidx/navigation/NavController` instance from various common places in your application, or for performing navigation in response to UI events.

## Summary

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/Navigation` | `https://developer.android.com/reference/androidx/navigation/Navigation#INSTANCE()` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.OnClickListener.html` | `https://developer.android.com/reference/androidx/navigation/Navigation#createNavigateOnClickListener(androidx.navigation.NavDirections)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDirections directions)` Create an `https://developer.android.com/reference/android/view/View.OnClickListener.html` for navigating to a destination via a generated `https://developer.android.com/reference/androidx/navigation/NavDirections`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.OnClickListener.html` | `https://developer.android.com/reference/androidx/navigation/Navigation#createNavigateOnClickListener(kotlin.Int,android.os.Bundle)(@https://developer.android.com/reference/androidx/annotation/IdRes int resId, https://developer.android.com/reference/android/os/Bundle.html args)` Create an `https://developer.android.com/reference/android/view/View.OnClickListener.html` for navigating to a destination. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavController` | `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.view.View)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view)` Find a `https://developer.android.com/reference/androidx/navigation/NavController` given a local `https://developer.android.com/reference/android/view/View.html`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavController` | `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity, @https://developer.android.com/reference/androidx/annotation/IdRes int viewId)` Find a `https://developer.android.com/reference/androidx/navigation/NavController` given the id of a View and its containing `https://developer.android.com/reference/android/app/Activity.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/navigation/Navigation#setViewNavController(android.view.View,androidx.navigation.NavController)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/androidx/navigation/NavController controller)` Associates a NavController with the given View, allowing developers to use `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` and `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` with that View or any of its children to retrieve the NavController. |

## Public fields

### INSTANCE

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public static @NonNull Navigation INSTANCE
```

## Public methods

### createNavigateOnClickListener

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.1.0)

```
public static final @NonNull View.OnClickListener createNavigateOnClickListener(@NonNull NavDirections directions)
```

Create an `https://developer.android.com/reference/android/view/View.OnClickListener.html` for navigating to a destination via a generated `https://developer.android.com/reference/androidx/navigation/NavDirections`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDirections directions` | directions that describe this navigation operation |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.OnClickListener.html` | a new click listener for setting on an arbitrary view |

### createNavigateOnClickListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
public static final @NonNull View.OnClickListener createNavigateOnClickListener(@IdRes int resId, Bundle args)
```

Create an `https://developer.android.com/reference/android/view/View.OnClickListener.html` for navigating to a destination. This supports both navigating via an `https://developer.android.com/reference/androidx/navigation/NavDestination#getAction(kotlin.Int)` and directly navigating to a destination.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int resId` | an `https://developer.android.com/reference/androidx/navigation/NavDestination#getAction(kotlin.Int)` id or a destination id to navigate to when the view is clicked |
| `https://developer.android.com/reference/android/os/Bundle.html args` | arguments to pass to the final destination |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.OnClickListener.html` | a new click listener for setting on an arbitrary view |

### findNavController

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
public static final @NonNull NavController findNavController(@NonNull View view)
```

Find a `https://developer.android.com/reference/androidx/navigation/NavController` given a local `https://developer.android.com/reference/android/view/View.html`.

This method will locate the `https://developer.android.com/reference/androidx/navigation/NavController` associated with this view. This is automatically populated for views that are managed by a `https://developer.android.com/reference/androidx/navigation/NavHost` and is intended for use by various `https://developer.android.com/reference/android/view/View.OnClickListener.html` interfaces.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view` | the view to search from |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavController` | the locally scoped `https://developer.android.com/reference/androidx/navigation/NavController` to the given view |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the given view does not correspond with a `https://developer.android.com/reference/androidx/navigation/NavHost` or is not within a NavHost. |

### findNavController

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
public static final @NonNull NavController findNavController(@NonNull Activity activity, @IdRes int viewId)
```

Find a `https://developer.android.com/reference/androidx/navigation/NavController` given the id of a View and its containing `https://developer.android.com/reference/android/app/Activity.html`. This is a convenience wrapper around `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)`.

This method will locate the `https://developer.android.com/reference/androidx/navigation/NavController` associated with this view. This is automatically populated for the id of a `https://developer.android.com/reference/androidx/navigation/NavHost` and its children.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | The Activity hosting the view |
| `@https://developer.android.com/reference/androidx/annotation/IdRes int viewId` | The id of the view to search from |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavController` | the `https://developer.android.com/reference/androidx/navigation/NavController` associated with the view referenced by id |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the given viewId does not correspond with a `https://developer.android.com/reference/androidx/navigation/NavHost` or is not within a NavHost. |

### setViewNavController

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0)

```
public static final void setViewNavController(@NonNull View view, NavController controller)
```

Associates a NavController with the given View, allowing developers to use `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` and `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` with that View or any of its children to retrieve the NavController.

This is generally called for you by the hosting `https://developer.android.com/reference/androidx/navigation/NavHost`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view` | View that should be associated with the given NavController |
| `https://developer.android.com/reference/androidx/navigation/NavController controller` | The controller you wish to later retrieve via `https://developer.android.com/reference/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` |