# 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)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/navigation/Navigation "View this page in Java") Common/AllAndroid/JVMJavaScript
- Cmn

  ```
  object Navigation
  ```

*** ** * ** ***

Entry point for navigation operations.

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

## Summary

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/android/view/View.OnClickListener.html` | `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#createNavigateOnClickListener(androidx.navigation.NavDirections)(directions: https://developer.android.com/reference/kotlin/androidx/navigation/NavDirections)` 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/kotlin/androidx/navigation/NavDirections`. | android |
| `https://developer.android.com/reference/android/view/View.OnClickListener.html` | `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#createNavigateOnClickListener(kotlin.Int,android.os.Bundle)(resId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, args: https://developer.android.com/reference/android/os/Bundle.html?)` Create an `https://developer.android.com/reference/android/view/View.OnClickListener.html` for navigating to a destination. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` | `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#findNavController(android.view.View)(view: https://developer.android.com/reference/android/view/View.html)` Find a `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` given a local `https://developer.android.com/reference/android/view/View.html`. | android |
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` | `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)(activity: https://developer.android.com/reference/android/app/Activity.html, viewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Find a `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` given the id of a View and its containing `https://developer.android.com/reference/android/app/Activity.html`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#setViewNavController(android.view.View,androidx.navigation.NavController)(view: https://developer.android.com/reference/android/view/View.html, controller: https://developer.android.com/reference/kotlin/androidx/navigation/NavController?)` Associates a NavController with the given View, allowing developers to use `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` with that View or any of its children to retrieve the NavController. | android |

## Public functions

### createNavigateOnClickListener

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

```
fun createNavigateOnClickListener(directions: NavDirections): View.OnClickListener
```

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/kotlin/androidx/navigation/NavDirections`.

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

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

### createNavigateOnClickListener

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

```
fun createNavigateOnClickListener(resId: @IdRes Int, args: Bundle? = null): View.OnClickListener
```

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/kotlin/androidx/navigation/NavDestination#getAction(kotlin.Int)` and directly navigating to a destination.

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

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

### findNavController

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

```
fun findNavController(view: View): NavController
```

Find a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/navigation/NavController` associated with this view. This is automatically populated for views that are managed by a `https://developer.android.com/reference/kotlin/androidx/navigation/NavHost` and is intended for use by various `https://developer.android.com/reference/android/view/View.OnClickListener.html` interfaces.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` | the locally scoped `https://developer.android.com/reference/kotlin/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/kotlin/androidx/navigation/NavHost` or is not within a NavHost. |

### findNavController

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

```
fun findNavController(activity: Activity, viewId: @IdRes Int): NavController
```

Find a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)`.

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

| Parameters |
|---|---|
| `activity: https://developer.android.com/reference/android/app/Activity.html` | The Activity hosting the view |
| `viewId: @https://developer.android.com/reference/kotlin/androidx/annotation/IdRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The id of the view to search from |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigation/NavController` | the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/navigation/NavHost` or is not within a NavHost. |

### setViewNavController

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

```
fun setViewNavController(view: View, controller: NavController?): Unit
```

Associates a NavController with the given View, allowing developers to use `https://developer.android.com/reference/kotlin/androidx/navigation/Navigation#findNavController(android.app.Activity,kotlin.Int)` and `https://developer.android.com/reference/kotlin/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/kotlin/androidx/navigation/NavHost`.

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