> Documentation index: https://developer.android.com/reference/llms.txt

# Navigation

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/webkit/Navigation.java+class:androidx.webkit.Navigation) Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

*** ** * ** ***


```
public final class Navigation
```

<br />

*** ** * ** ***

The Navigation instance passed by `NavigationListener`.

The same object will be used by the relevant callbacks for the same navigation, allowing the instance itself to be used as a key/ID to connect the callbacks for the same navigation through `equals` and `hashCode`.

The return values of `wasInitiatedByPage`, `isReload`, `isHistory`, `isBack`, `isForward` and `isRestore` are constant for a given Navigation. For the other methods:

- `getPage`, `didCommit` and `didCommitErrorPage` will only change when `onNavigationCompleted` is called.
- `getUrl` will only change when `onNavigationRedirected` is called.

## Summary

| ### Public methods |
|---|---|
| `@NonNull NavigationState` | `@AnyThread @RequiresFeature(name = WebViewFeature.NAVIGATION_LISTENER_NAVIGATION_STATE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") captureState()` Takes a snapshot of the navigation's state. |
| `boolean` | `didCommit()` Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc). |
| `boolean` | `didCommitErrorPage()` Indicates whether the navigation committed an error page. |
| `@Nullable Page` | `getPage()` Returns the Page that the navigation commits into. |
| `int` | `getStatusCode()` Returns the status code received by the navigation. |
| `@NonNull String` | `getUrl()` Returns the URL of this navigation. |
| `@Nullable WebResourceErrorCompat` | `@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") getWebResourceError()` Navigation error information for the navigation load. |
| `boolean` | `isBack()` Indicates whether the navigation is a history back navigation. |
| `boolean` | `isForward()` Indicates whether the navigation is a history forward navigation. |
| `boolean` | `isHistory()` Indicates whether the navigation is a history navigation. |
| `boolean` | `isReload()` Indicates whether the navigation is a reload navigation. |
| `boolean` | `isRestore()` Indicates whether the navigation is a restore navigation after calling `restoreState`. |
| `boolean` | `isSameDocument()` Indicates whether the navigation is a same-document navigation. |
| `boolean` | `wasInitiatedByPage()` Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls). |

## Public methods

### captureState

Added in [1.19.0-alpha02](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.19.0-alpha02)

```
@AnyThread
@RequiresFeature(name = WebViewFeature.NAVIGATION_LISTENER_NAVIGATION_STATE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @NonNull NavigationState captureState()
```

Takes a snapshot of the navigation's state. This allows you to hold a consistent representation of the navigation at a certain point in time, as the Navigation object gets updated as the navigation progresses.

| Returns |
|---|---|
| `@NonNull NavigationState` | The immutable `NavigationState` object. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `NAVIGATION_LISTENER_NAVIGATION_STATE` feature is not supported. This should be checked before use with `isFeatureSupported`. |

### didCommit

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean didCommit()
```

Indicates whether the navigation committed (i.e., did not get aborted/return 204/etc).

| Returns |
|---|---|
| `boolean` | True if committed, false otherwise. |

### didCommitErrorPage

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean didCommitErrorPage()
```

Indicates whether the navigation committed an error page.

| Returns |
|---|---|
| `boolean` | True if an error page was committed, false otherwise. |

### getPage

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public @Nullable Page getPage()
```

Returns the Page that the navigation commits into.

Note: This method will initially return `null` when navigation begins. If the navigation successfully commits a page, this method will return the corresponding `Page` object. This could be a newly created `Page` or a previously seen `Page` in the case of BFCache (Back/Forward Cache).

Note: Once this method returns a non-null `Page` object for a specific navigation, it will always return the same `Page` object for that navigation.

| Returns |
|---|---|
| `@Nullable Page` | The `Page` object, or `null` if the navigation does not commit or result in a Page (e.g., [204](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204)/download). |

### getStatusCode

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public int getStatusCode()
```

Returns the status code received by the navigation.

| Returns |
|---|---|
| `int` | The HTTP status code. |

### getUrl

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.15.0)

```
public @NonNull String getUrl()
```

Returns the URL of this navigation.

| Returns |
|---|---|
| `@NonNull String` | The URL of this navigation as a String. |

### getWebResourceError

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.16.0)

```
@RequiresFeature(name = WebViewFeature.NAVIGATION_GET_WEB_RESOURCE_ERROR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @Nullable WebResourceErrorCompat getWebResourceError()
```

Navigation error information for the navigation load.

| Returns |
|---|---|
| `@Nullable WebResourceErrorCompat` | The `WebResourceErrorCompat` object, or `null` if there is no error for this navigation. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `NAVIGATION_GET_WEB_RESOURCE_ERROR` feature is not supported. This should be checked before use with `isFeatureSupported`. |

### isBack

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isBack()
```

Indicates whether the navigation is a history back navigation.

| Returns |
|---|---|
| `boolean` | True if back navigation, false otherwise. |

### isForward

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isForward()
```

Indicates whether the navigation is a history forward navigation.

| Returns |
|---|---|
| `boolean` | True if forward navigation, false otherwise. |

### isHistory

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isHistory()
```

Indicates whether the navigation is a history navigation.

| Returns |
|---|---|
| `boolean` | True if history, false otherwise. |

### isReload

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isReload()
```

Indicates whether the navigation is a reload navigation.

| Returns |
|---|---|
| `boolean` | True if reload, false otherwise. |

### isRestore

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isRestore()
```

Indicates whether the navigation is a restore navigation after calling `restoreState`.

| Returns |
|---|---|
| `boolean` | True if session restore, false otherwise. |

### isSameDocument

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean isSameDocument()
```

Indicates whether the navigation is a same-document navigation.

| Returns |
|---|---|
| `boolean` | True if same-document, false otherwise. |

### wasInitiatedByPage

Added in [1.14.0](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.14.0)

```
public boolean wasInitiatedByPage()
```

Indicates whether the navigation is initiated by the page/renderer (e.g., link clicks, JS script) instead of the browser/app (e.g., loadUrl calls).

| Returns |
|---|---|
| `boolean` | True if page-initiated, false otherwise. |